Convert Drawable to Bitmap:
1 | Bitmap bitmap= BitmapFactory.decodeResource(getResources(), R.drawable.image); |
1 | Bitmap bitmap= BitmapFactory.decodeResource(getResources(), R.drawable.image); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(getResources(), R.id.myimage, options); int imageHeight = options.outHeight; int imageWidth = options.outWidth; String imageType = options.outMimeType; Now scale down the bitmap and load into memory.I use decodeResource() method here but you can use any method(decodeFile etc).So now using following function scale down bitmap public static int calculateInSampleSize( BitmapFactory.Options options, int reqWidth, int reqHeight) { // Raw height and width of image final int height = options.outHeight; final int width = options.outWidth; int inSampleSize = 1; if (height > reqHeight || width > reqWidth) { if (width > height) { inSampleSize = Math.round((float)height / (float)reqHeight); } else { inSampleSize = Math.round((float)width / (float)reqWidth); } } return inSampleSize; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, int reqWidth, int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(res, resId, options); } |
1 | android:scrollbars="vertical" |
1 | txtScroll.setMovementMethod(new ScrollingMovementMethod()); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | Layout : main.xml <? xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:background="#fff" android:gravity="center" android:layout_height="fill_parent"> <TextView android:id="@+id/Title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:textSize="30sp" android:textColor="#cd6000" android:textStyle="bold" android:text="My Splash Page" /> <ImageView android:id="@+id/Loading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/loading" /> </LinearLayout> |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | package com.app; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; import android.widget.TextView; /** * @author Rajendhiran. E * Feb 10, 2013 11:10:52 PM */ public class SplashScreen extends Activity { TextView Title; ImageView Loading; Animation anim; Handler h; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); init(); process(); } /* @author Rajendhiran. E, Feb 10, 2013 11:14:24 PM */ private void init() { Title = (TextView) findViewById(R.id.Title); Loading = (ImageView) findViewById(R.id.Loading); anim = AnimationUtils.loadAnimation(SplashScreen.this, R.drawable.rotate); Loading.startAnimation(anim); h = new Handler(); } /* @author Rajendhiran. E, Feb 10, 2013 11:19:35 PM */ private void process() { h.postDelayed(new Runnable() { public void run() { Loading.clearAnimation(); finish(); startActivity(new Intent(SplashScreen.this,SecondActivity.class)); } }, 1000); } } |
1: <?xml version="1.0" encoding="utf-8"?>
2: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3: android:orientation="vertical"
4: android:layout_width="fill_parent"
5: android:layout_height="fill_parent"
6: >
7: <TextView
8: android:id="@+id/countdown"
9: android:layout_width="fill_parent"
10: android:layout_height="wrap_content"
11: android:text="00:00:00"
12: />
13: <Button
14: android:id="@+id/TimeBtn"
15: android:layout_width="fill_parent"
16: android:layout_height="wrap_content"
17: android:text="Count down Start!" />
18: </LinearLayout>
1: package com.app.poc;
2: import java.text.SimpleDateFormat;
3: import java.util.TimeZone;
4: import android.app.Activity;
5: import android.os.Bundle;
6: import android.os.CountDownTimer;
7: import android.util.Log;
8: import android.view.View;
9: import android.widget.Button;
10: import android.widget.TextView;
11: public class POCApp extends Activity
12: {
13: public Button TimeBtn;
14: public TextView Time;
15: MyCounter timer;
16: public void onCreate(Bundle savedInstanceState)
17: public void onCreate(Bundle savedInstanceState)
18: {
19: super.onCreate(savedInstanceState);
20: setContentView(R.layout.main);
21: init();
22: process();
23: }
24: private void process()
25: {
26: TimeBtn.setOnClickListener(new View.OnClickListener()
27: {
28: public void onClick(View arg0)
29: {
30: if(timer!=null)
31: timer.cancel();
32: timer = new MyCounter(3800*1000,1000);
33: timer.start();
34: //Toast.makeText(POCApp.this, disHour+":"+disMinu+":"+disSec, Toast.LENGTH_LONG).show();
35: }
36: });
37: }
38: /**
39: * @author Rajendhiran. E
40: * Jan 16, 20134:46:24 PM
41: */
42: private void init()
43: {
44: TimeBtn = (Button) findViewById(R.id.TimeBtn);
45: Time = (TextView) findViewById(R.id.countdown);
46: }
47: /**
48: * @author Rajendhiran. E
49: * Jan 16, 20134:46:25 PM
50: */
51: class MyCounter extends CountDownTimer
52: {
53: SimpleDateFormat mSimpleDateFormat;
54: public MyCounter(long millisInFuture, long countDownInterval)
55: {
56: super(millisInFuture, countDownInterval);
57: mSimpleDateFormat= new SimpleDateFormat("HH:mm:ss");
58: mSimpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
59: }
60: @Override
61: public void onFinish()
62: {
63: Log.d("Timer Completed: ","Completed!");
64: Time.setText("00:00:00");
65: }
66: @Override
67: public void onTick(long millisUntilFinished)
68: {
69: Time.setText(mSimpleDateFormat.format(millisUntilFinished));
70: }
71: }
1 2 3 4 5 | <resources> <string name="zero"> No Items on the Stall!</string> <string name="one">Only One Item on the Stall</string> <string name="moreThanOne">There are %d Items on the Stall</string> </resources> |
1 2 3 4 5 6 7 | if (ItemsCount ==0) result= getString(R.string.zero); else if (ItemsCount ==1) result= getString(R.string.one); else if (ItemsCount >1) result= getString(R.string.moreThanOne, ItemsCount); textView.setText(result); |
1 2 3 4 5 6 | <resources> <plurals name="numberOfItems"> <item quantity="one">Only %d Item</item> <item quantity= "other">%d Items!</item> </plurals> </resources> |
1 2 3 | int ItemsCount= 20; String result = getResources().getQuantityString(R.plurals.numberOfItems, ItemsCount,ItemsCount); textView.setText(result); |
1 2 | InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0); |
1 2 | InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(singleedittext.getWindowToken(),0); |