Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Import project Android Eclipse


AD MOB

Import a new Android project for example downloaded from internet via Eclipse into project folder.

  1. Right click into projects explorer in Eclipse and select Import

  2. Android

  3. Existing Android Code Into Workspace

  4. Root Directory (select folder of downloaded project)

  5. Check your downloaded project

  6. Check Copy project into Workspace

  7. Finish (press)





397LW NO topic_id




AD

Další témata ....(Topics)


41

Preferences settings save open read write application Android example | preferences-settings-save-open-red-application-android-example


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();
    	}
    	
    }	
}
322

View overrides onTouchEvent but not performClick | view-overrides-ontouchevent-but-not-performclick



public class Panel extends SurfaceView implements SurfaceHolder.Callback {
//............... code
//............... some code
   /**
     * Process the MotionEvent.
     */
    @Override
    public boolean onTouchEvent(MotionEvent event) {
    	
        synchronized (getHolder()) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
            	performClick();
             } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
            	if(_currentGraphic==null)return true;
                
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
            }
            return true;
        }
    }
/////////////////////////////
 @Override
 public boolean performClick() {
  // Calls the super implementation, which generates an AccessibilityEvent
        // and calls the onClick() listener on the view, if any
        super.performClick();

        // Handle the action for the custom click here

        return true;
 }

}

131

Draw color line set stroke width Android basic example | draw-line-android-basic-example


Canvas, drawLine(), setStrokeWidth(), Paint, setAntiAlias(boolean), onDraw()

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.YELLOW);
			Paint p = new Paint();
			// smooths
			p.setAntiAlias(true);
			p.setColor(Color.RED);
			p.setStrokeWidth(4.5f);
			// opacity
			p.setAlpha(0x80); //
			// drawLine (float startX, float startY, float stopX, float stopY,
			// Paint paint)
			canvas.drawLine(0, 0, 40, 40, p);
			canvas.drawLine(40, 0, 0, 40, p);

		}

	}
}
130

Bitmap get Bitmap from resource Android example | bitmap-get-bitmap-from-resource-android-example


PNG, GIF, BMP, JPG

// //www.apache.org/licenses/LICENSE-2.0

// 1.)  Bitmap from stream
            InputStream is = context.getResources().openRawResource(R.drawable.my_image);
            mBitmap = BitmapFactory.decodeStream(is);
           

// 2.) 
            Bitmap ball = BitmapFactory.decodeResource(getResources(), R.drawable.ball);
            int dstWidth =120;
            int dstHeight = 120;
            mBitmap = Bitmap.createScaledBitmap(ball, dstWidth, dstHeight, true);

// 3.)
Bitmap  mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);


        Bitmap  mBitmap;
        Canvas  mCanvas;
        Paint   mBitmapPaint;
            
            mBitmap = Bitmap.createBitmap(320, 480, Bitmap.Config.ARGB_8888);
            mCanvas = new Canvas(mBitmap);
            mBitmapPaint = new Paint(Paint.DITHER_FLAG);

// 4.)
          Bitmap  mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
          Canvas  mCanvas.setBitmap(mBitmap);
            mCanvas.drawColor(0xFFFFFFFF);

336

Android emulator freezes at startup create new virtual device | android-emulator-freezes-at-startup-create-new-virtual-device


If Android emulator freezes at startup, try create new virtual device with smaller memory and cpu usage, or select older version of Android, or buy new pc with higher performance.

  1. open AVD MANAGER

  2. press Create Virtual Device

  3. select Device with small memory usage (e.g. 480x800 of resolution) - Next

  4. check - Show downloadable ....

  5. Download - lower version of system Android, select, press - Next

  6. check data, Show Advanced Settings, check Use host... and press Finish


android-studio-create-virtual-device-emulator


Editace: 2014-07-13 10:25:38
Počet článků v kategorii: 397
Url:import-project-android-eclipse

AD
11 Share
Share
Tweet