Import project Android Eclipse
Import a new Android project for example downloaded from internet via Eclipse into project folder.
- Right click into projects explorer in Eclipse and select Import
- Android
- Existing Android Code Into Workspace
- Root Directory (select folder of downloaded project)
- Check your downloaded project
- Check Copy project into Workspace
- Finish (press)
396LW NO topic_id
AD
Další témata ....(Topics)
Canvas, drawCircle(), Paint, onDraw(), setStrokeWidth(), setStyle()
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
// CONSTRUCTOR
public SampleView(Context context) {
super(context);
setFocusable(true);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.CYAN);
Paint p = new Paint();
// smooths
p.setAntiAlias(true);
p.setColor(Color.RED);
p.setStyle(Paint.Style.STROKE);
p.setStrokeWidth(4.5f);
// opacity
//p.setAlpha(0x80); //
canvas.drawCircle(50, 50, 30, p);
}
}
}
Shortcut
Windows
Ctrl + Alt + L (format selection or all page)
Ctrl + Alt + Shift + L (show a dialog)
Linux
Ctrl + Windows Key + Alt + L
From menu Code
Code > Reformat Code
Windows
Ctrl + Alt + L (format selection or all page)
Ctrl + Alt + Shift + L (show a dialog)
Linux
Ctrl + Windows Key + Alt + L
From menu Code
Code > Reformat Code
/* Copyright (C) 2011 The Android Open Source Project
//www.apache.org/licenses/LICENSE-2.0
*/
public class MainActivity extends Activity {
private ImageView imageView;
private Button button1;
Drawable bitmapOrg;
private final int[] mColors =
{Color.BLUE, Color.GREEN, Color.RED, Color.LTGRAY, Color.MAGENTA, Color.CYAN,
Color.YELLOW, Color.WHITE};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
imageView = (ImageView)findViewById(R.id.imageView1);
button1 = (Button)findViewById(R.id.button1);
bitmapOrg = this.getResources().getDrawable(R.drawable.flower_blue);
button1.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
int mColor = (int) Math.floor(Math.random() * mColors.length);
bitmapOrg.setColorFilter(mColors[mColor], PorterDuff.Mode.MULTIPLY);
imageView.setImageDrawable(bitmapOrg);
imageView.invalidate();
}
});
}
}
Android app setup preferences, settings, open, read, write, onStop(), onPause(), getSharedPreferences(), SharedPreferences.Editor getInt(), getBoolean(), getString() , putInt(), putString(), putBoolean() example source code.
import android.content.SharedPreferences;
public class MainClass extends Activity {
public static final String PREFERENCES_NAME = "MyPrefsFile";
String myNewString;
int myNewInt;
Boolean myNewBool;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// read old settings if exist
SharedPreferences settings = getSharedPreferences(PREFERENCES_NAME, 0);
String sDefault = "Hello!";
String sStringFromPrefFile = settings.getString("myString", sDefault); // new text or default Hello!
int nDefaultIndex = 2; //
int nIndexFromPrefFile = settings.getInt("myInt", nDefaultIndex); // 4 or default 2
Boolean bDefault = false;
Boolean bFromPrefFile = settings.getBoolean("silentMode", bDefault); // true or default false
// new settings will saved in onStop or onPause
myNewString = "new text";
myNewInt = 4;
myNewBool = true;
}
@Override
protected void onPause() {
super.onPause();
Toast.makeText(getApplicationContext(), "onPause "
, Toast.LENGTH_SHORT).show();
savePreferences();
}
@Override
protected void onStop() {
super.onStop();
savePreferences();
}
/**save settings*/
public void savePreferences(){
try {
SharedPreferences settings = getSharedPreferences(PREFERENCES_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("myString", myNewString);
editor.putInt("nMyInt", myNewInt);
editor.putBoolean("silentMode", myNewBool); //
editor.commit();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public boolean isConnected() {
try {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
return cm.getActiveNetworkInfo().isConnectedOrConnecting();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.e("isConnected", e.getMessage());
Toast.makeText(getApplicationContext(), e.getMessage(),
Toast.LENGTH_LONG).show();
return false;
}
Editace: 2014-07-13 10:25:38
Počet článků v kategorii: 396
Url:import-project-android-eclipse