Thursday, 16 June 2016

Creating circle inside circle shape in android using xml file

Creating circle inside circle shape in android using xml file

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Larger blue circle in back -->
    <item>
        <shape android:shape="oval">
            <solid android:color="#f00"/>
            <size
                android:width="15dp"
                android:height="15dp"/>
        </shape>
    </item>
    <!-- Smaller red circle in front -->
    <item>
        <shape android:shape="oval">
            <!-- transparent stroke = larger_circle_size - smaller_circle_size -->
            <stroke android:color="@android:color/transparent"
                android:width="10dp"/>
            <solid android:color="#fff"/>
            <size
                android:width="1dp"
                android:height="1dp"/>
        </shape>
    </item>
    <item>
        <shape android:shape="oval">
            <!-- transparent stroke = larger_circle_size - smaller_circle_size -->
            <stroke android:color="@android:color/transparent"
                android:width="11dp"/>
            <solid android:color="#f00"/>
            <size
                android:width="1dp"
                android:height="1dp"/>
        </shape>
    </item>
</layer-list>

Above code will generate shape given below


Monday, 30 November 2015

Garbage Collection Codes explaination while processing bitmaps in android

GC_FOR_MALLOC means that the GC was triggered because there wasn’t enough memory left on the heap to perform an allocation. Might be triggered when new objects are being created.

GC_EXPLICIT means that the garbage collector has been explicitly asked to collect, instead of being triggered by high water marks in the heap. Happens all over the place, but most likely when a thread is being killed or when a binder communication is taken down. Also when you use System.gc();

GC_CONCURRENT Triggered when the heap has reached a certain amount of objects to collect. This is the default garbage collection in Android version  2.2 and above.

GC_EXTERNAL_ALLOC means that the VM is trying to reduce the amount of memory used for collectable objects, to make room for more non-collectable. External Alloc is a telltale sign you may have too many bitmaps.

Check your Android Studio's/Eclipse's  Logcat which GC code it is showing and get explanation above.
Thanks and enjoy and please keep commenting.  

Monday, 17 August 2015

Setting tokens/terms to be logged for every message using log4j.properties

Format Specifier Description
%C The complete class name that has invoked the log
%d The timestamp when log request is invoked. Further customized using java's DateFormat style of abbreviations like %d{yyyy-MM-dd HH:mm:ss,SSS} which incidentally is the default used.
%F The source file name that makes the log request.
%l The source file name, method name and line number where log request is made.
%L The line number of the source file where log request is made.
%m The actual message logged.
%M The method name that makes the log request.
%n New line character
%p The log level used in the log request.
%r The time elapsed between start of the application and the log request in milliseconds.
%t The java thread name that nakes the log request.

Thursday, 6 March 2014

How to use Scrapbook Page in eclipse

Today i am going to show you how to use Scrapbook page for testing  a block of code for it's output before implementing it into your project .
Actually Scrapbook page use to test sample code for its output .it's a very convenient way to check code instantly.

Step-1 Go to File ---New---java project
give the name of you project , i am giving "ScrapbookTest" and click finish button


Step-2 Now your java project has created select this java project and go to File ---New---others---java---Java Run/Debug---Scrapbook Page
click on this Scrapbook Page option and select the parent folder and file name and click finish.

Step-3 now you can see you file as dummy.jpage add code for example:

System.out.print("I am checking Scrapbook Page");

select this line and right click on it and select execute.


now you can see the output on the Console as the image shown below.


Thats it 
please leave your valuable feedback

Happy Coding and Blogging.........

Sunday, 2 March 2014

Strike-Through of Text on UI Component

Today i am going to show you how to Strike through the text attached UI Component of Android As shown below

Step-1   First write the code for XML layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world" />

    <RadioButton
        android:id="@+id/radioButton1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/textView"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="44dp"
        android:text="RadioButton" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/radioButton1"
        android:layout_alignLeft="@+id/textView"
        android:layout_marginBottom="23dp"
        android:text="Button" />

</RelativeLayout>
Step-2  write the below code in MainActivity.java
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView strike_through = (TextView)findViewById(R.id.textView);
Button btn = (Button)findViewById(R.id.button1);
RadioButton radio_btn = (RadioButton)findViewById(R.id.radioButton1);
strike_through.setText("This is strike-thru");
// Strike-through code for TextView
strike_through.setPaintFlags(strike_through.getPaintFlags()|Paint.STRIKE_THRU_TEXT_FLA);
// Strike-through code for Button
 btn.setPaintFlags(btn.getPaintFlags()|Paint.STRIKE_THRU_TEXT_FLAG);
//Strike-through code for RadioButton
  radio_btn.setPaintFlags(radio_btn.getPaintFlags()|Paint.STRIKE_THRU_TEXT_FLAG);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}
Step-3 for removing strike-through you can use below code for UIcomponent
yourUIcomponent.setPaintFlags(yourUIcomponent.getPaintFlags()|Paint.STRIKE_THRU_TEXT_FLAG);


Thats it! Run your project and see result as shown above in image.

please give your valuable feedback.
Enjoy Coding and blogging!! 

Friday, 28 February 2014

easy way to integrate PayPal SDK in your Android App for in App purchase


  1. first go the this link paypal SDK for downloading updated PayPal SDK (Version 2.0.1)for Android.
  2. Go to file Tab in eclipse and click import and select Existing Project into Workspabe under General folder click next and check select archive file radio button then click browse the source.zip from previous link and then click finish.
  3. Now you have import the source.zip file and you can see PayPalSDKExample  project into your packageExplorer. if you find Error then you could rewrite target in project.properties and android:targetSdkVersion in AndroidManifest.xml.
  4. After step 3 save and clean the project and  removed the error from project. 
  5. Now you can run your project without communicating the PayPal Server.for sanbox testing go through step-6 to step-17  also.
  6. open the SampleActivity.java file you could see the private static final String CONFIG_ENVIRONMENT = PayPalConfigurnatio.ENVIRONMENT_NO_NETWORK;  
  7. the line shown in step-5 indicate the PayPal Server Enviorment where we test our App there are 2 more  options  apart from above which is ENVIRONMENT_PRODUCTION   and     ENVIRONMENT_SANDBOX. 
  8. for publishing app into market you would need to use PayPalConfigurnatio.ENVIRONMENT_PRODUCTION environment for real time payment this is also known as Live Environment. while  PayPalConfigurnatio.ENVIRONMENT_SANDBOX used for testing app without real time payment.
  9. Second line You could see is  private static final String CONFIG_CLIENT_ID = "credential from developer.paypal.com";  
  10. Your mobile integration requires different client_id values for each environment: Live and Test (Sandbox).
  11. Go to this link register your app for register your app for getting client_id
  12. if you have PayPal Account the you can directly logged in and follow instruction for registering app otherwise you would need to sign up .
  13. after step-12 you would click on create app button and follow the step to register your app and get client_id 
  14. replace CONFIG_CLIENT_ID with your app client_id
  15. create test account from this link whose type would be personal not Bussiness
  16. finally change CONFIG_ENVIRONMENT value  to PayPalConfigurnatio.ENVIRONMENT_SANDBOX
  17. finally run your app and test in SANDBOX environment with test account without any real Transaction 

please give me feedback and enjoy coding and blogging