Tuesday 27 June 2017

Name Live Wallpaper Example Android

Android Live Wallpaper:
This tutorial describes about how to implement the live wallpaper for android.
Steps to develop live wallpaper:
Step 1:
·         Create an XML folder in resource(res) folder.
Right click on res->new->directory-> enter xml and click ok.
·         Create an xml resource file for wallpaper as follows wallpaper.xml
write your description and icon

<wallpaper xmlns:android="http://schemas.android.com/apk/res/android"
   
android:description="@string/wallpaper_service_description"
   
android:settingsActivity="blog.thiru.livewallpaper.WallpaperSettingsActivity"
   
android:thumbnail="@drawable/thumb" />

Here description attribute is the wallpaper description will be shown in list of wallpapers and thumbnail is the icon that displays in wallpaper list. If you want Settings Activity create a settings activity by extending AppCompatActivity. If you don’t want to change the settings of the live wallpapers, just remove the android:settingsActivity attribute.

Step 2:
Create Wallpaper settings activity.
There are 3 ways to create the wallpaper settings activity

·         Create an activity extending the AppcompatActivity
·         Create a class and extends PreferenceFragment.
·         Create a class and extend to PreferenceActivity.
Here I used first approach.

Step 3:   WallpaperService Class

Create a Service class which extends WallpaperService class, which is base class for all live wallpapers in the systems. Need to implement onCreateEngine() method and return an object o type android.service.wallpaper.WallpaperService.Engine. The Engine class has few Life cycle methods such as,
  • onCreate();
  • onSurfaceCreated();
  • onVisibilityChanged();
  • onOffsetChanged();
  • onTouchEvent();
  • onCommand();
public class Wallpaper extends WallpaperService {
    private static final String TAG = "Wallpaper";
    int positionX, postionY;
   
@Override     public void onCreate() {         super.onCreate();     }     @Override     public void onDestroy() {         super.onDestroy();     }     @Override     public Engine onCreateEngine() {         return new WallpaperEngine();     }
    class WallpaperEngine extends Engine {
      private final Handler handler = new Handler();
      private final Runnable drawRunner = new Runnable() {
         @Override           public void run() {
            draw();
           }
          };
      WallpaperEngine() {
       nameImage = Utils.bitmap = textBitmap;
       bgImage = BitmapFactory.decodeResource(getResources(),R.drawable.background);
       postionX=-130; 
       postionY=200; 
       }
   public void onCreate(SurfaceHolder surfaceHolder){
        super.onCreate(surfaceHolder);
    }
    @Override   
    public void onVisibilityChanged(boolean mVisible)
     {
        this.mVisible = mVisible;
        if (mVisible){
            handler.post(drawRunner);
        }
        else
            handler.removeCallbacks(drawRunner);
     }
    @Override    public void onSurfaceDestroyed(SurfaceHolder holder){
        super.onSurfaceDestroyed(holder);
        this.mVisible = false;
        handler.removeCallbacks(drawRunner);
    }
    public void onOffsetsChanged(float xOffset,float yOffset,float xStep,float yStep,int xPixels,int yPixels){
        draw();
    }
    void draw()
    {
        final SurfaceHolder holder = getSurfaceHolder();
        Canvas c = null;
        try{
            c = holder.lockCanvas();
            c.drawColor(Color.BLACK);
            if (c != null){
                c.drawBitmap(bgImage, 0, 0, null);
                c.drawBitmap(nameImage, postionX,postionY, null);
                c.drawBitmap(nameImage, postionY,postionX, null);
                int width=c.getWidth();
                if( postionX>width+100){
                   postionX=-130;
                }
               postionX = postionX+1;
               postionY = postionY+1;
            }
        }
        finally{  
            if (c != null)
                holder.unlockCanvasAndPost(c);
        }
        handler.removeCallbacks(drawRunner);
        if (mVisible){
            handler.postDelayed(drawRunner, 10); // delay 10 mileseconds        }
    }
}

Step 4:
Here is the Main Activity:
public class HomeActivity extends AppCompatActivity{
    private AlertDialog.Builder alertDialog;
    private View view;
    private EditText fontText;
    private TextView text1;
    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        text1 = (TextView) findViewById(R.id.txtToBitmap);
    }
    private void initDialog() {
        alertDialog = new AlertDialog.Builder(this);
        view = getLayoutInflater().inflate(R.layout.font_dialog, null);
        fontText = (EditText) view.findViewById(R.id.fontText);
        removeView();
        alertDialog.setView(view);
        alertDialog.setPositiveButton("Save", new DialogInterface.OnClickListener() {
            @Override            public void onClick(DialogInterface dialog, int which) {
                String font = fontText.getText().toString();
                if(!font.equals("")) {
                    text1.setText(font);
                    text1.setTypeface(Typeface.createFromAsset(
                            text1.getContext().getAssets(),
                            "fonts/chunq_dipped.ttf"));
                    text1.post(new Runnable() {
                        @Override                        public void run() {
                            Bitmap textBitmap = getBitmapFromView(text1);
                            Utils.bitmap = textBitmap;
                        }
                    });
                    Intent intent = new Intent(
                            WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
                    intent.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
                            new ComponentName(HomeActivity.this, MyWallpaperService.class));
                    startActivity(intent);
                }
                dialog.dismiss();
            }
        });
    }
    private void removeView() {
        if (view.getParent() != null) {
            ((ViewGroup) view.getParent()).removeView(view);
        }
    }
    public Bitmap getBitmapFromView(TextView view) {
        Bitmap returnedBitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(returnedBitmap);
        Drawable bgDrawable = view.getBackground();
        bgDrawable.draw(canvas);
        view.draw(canvas);
        return returnedBitmap;
    }
}
activity_home.xml:
<RelativeLayout    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"    
android:layout_height="match_parent"    
android:background="@drawable/home_bg"    
tools:context="com.ddrinfosystems.nameart.HomeActivity">
<TextView    
android:id="@+id/txtToBitmap"   
android:layout_width="wrap_content"    
android:layout_height="wrap_content"    
android:textSize="32sp"    
android:textColor="#FFFF00"    
android:visibility="invisible"
    android:layout_marginLeft="10dp"    
android:layout_marginStart="10dp"    
android:layout_marginBottom="70dp" />
</RelativeLayout>

font_dialog.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout    
xmlns:android="http://schemas.android.com/apk/res/android"    
android:orientation="vertical"    
android:layout_width="match_parent"    
android:layout_height="match_parent">
    <EditText        
android:id="@+id/fontText"        
android:layout_width="match_parent"       
android:layout_height="wrap_content"       
android:padding="16dp"        
android:hint="Enter your name"        android:layout_margin="16dp">
    </EditText>
</LinearLayout>

Utils class:
public class Utils {
    static Bitmap bitmap;
}
Step 5:
Setting up Manifest.xml
Live Wallpaper is a service, need to register the service in your manifest file. The Manifest file seems like..
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="blog.thiru.livewallpaper"
    android:versionCode="1"
    android:versionName="1.0" >
   <uses-sdk
       android:minSdkVersion="15"
       android:targetSdkVersion="25" />
    <uses-feature android:name="android.software.live_wallpaper" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/wallpaper_application_title"
        android:theme="@style/AppTheme" >
        <service
            android:name=".Wallpaper"
            android:label="@string/wallpaper_service_title"
            android:permission="android.permission.BIND_WALLPAPER" >
            <intent-filter>
                <action android:name="android.service.wallpaper.WallpaperService" />
            </intent-filter>
            <meta-data
                android:name="android.service.wallpaper"
                android:resource="@xml/wallpaper" />
        </service>
        <activity
            android:name=".WallpaperSettingsActivity"
            android:exported="true"
            android:label="@string/pref_screen_title" >
        </activity>
        <activity
            android:name=".WallpaperActivity"
            android:label="@string/wallpaper_application_title" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

Here it is just sample. You can customize the draw() method for your interest. 

Thursday 1 June 2017

Top Companies and their founders
1. Google— Larry Page & Sergey Brin 2. Facebook— Mark Zuckerberg 3. AAlkatel A3 Jeff Bezos

3. Yahoo— David Filo & Jerry Yang 4. Twitter— Jack Dorsey & Dick Costolo Sparx Canvas Shoes
5. Internet— Tim Berners-Lee 6. LinkedIn— Reid Hoffman, Allen Blue&Koonstantin Guericke 7. Email— Shiva Ayyadurai Click here for more details
8. Gtalk— Richard Wah-kan 9. Whatsapp— Brian Acton and Jan Koum 10. Hotmail— Sabeer Bhatia 11. Orkut— Buyukkokten 12. Wikipedia— Jimmy Wales 13. You tube— Steve Chen, Chad Hurley &JawedKarim 14. Rediffmail— Ajit Balakrishnan 15. Nimbuzz— Martin Smink & Evert Jaap Lugt 16. Myspace— Chris Dewolfe & Tom Anderson

17. Ibibo— Ashish Kashyap 18. OLX— Alec Oxenford & Fabrice Grinda 19. Skype— Niklas Zennstrom, JanusFriis & Reid Hoffman 20. Opera— Jon Stephenson von Tetzchner & Geir lvarsoy 21. Mozilla Firefox— Dave Hyatt & Blake Ross 22. Blogger— Evan Willams

Tuesday 23 May 2017


Kotlin:


  Now every android developer look towards Kotlin a new programming language officially announced by the Google inc. The special thing about the kotlin is supported for multi-platform libraries and ease of using programming language. But no worries about Java users using to develop in Java programming language. Android support both. Its inter-operable for Java and Kotlin as well. 






         Most of the training centers already started Kotlin training classes. Even they are offering discounts towards learning Kotlin. It has the great future ahead. Most of the developer migrate to Kotlin because it's simplicity and it is the product of Google. 

        
         The bad days have com to the Java. Even though it is a most using programming language, But technology is upgrading day to day. Java has it's own brand in market, it can be used for coming decades also. 





         The main reason to Kotlin come into the market is Java is the product of Oracle. So google wanted it's own platform to build applications. It doesn't want to depend on others. So this main reason to as Kotlin evolved.


Great deals at amazon Click here

           Hope this information helpful to you.

Learn more here

Thursday 6 April 2017

What is Xamarin.

                   
Xamarin is a Microsoft-owned SanFrancisco, California-based software company founded in May 2011 by the engineers that created Mono, Mono for Android and MonoTouch, which are cross-platform implementations of the Common Language Infrastructure (CLI) and Common Language Specification (CLS) (often called Microsoft .NET). CLI describes executable code and a runtime environment that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architecture.

Xamarin is a commercial software development tools that allow a user to develop applications for Android, iOS, and Windows using C# language and the .NET framework.
Xamarin allows us to code application logic once and then share it across both iOS and Android. Compare this to working in the native environments of the two platforms where the logic must be implemented once in Java for Android then the same logic implemented a second time in Objective-C for iOS.

            Xamarin Studio or Visual Studio is used to develop the applications. Basically, Xamarin Studio is for Mac users and the Visual Studio for windows platforms. In Xamarin Studio we have Xamarin.iOS and Xamarin.Android for different platforms to use native APIs. To build UI for the application we use Xamarin.Forms. It has a property that the code can share on Android and iOS as well.



Xamarin Products:
1.    Xamarin platform
2.    Xamarin.Forms
3.    Xamarin Test Cloud
4.    Xamarin for Visual Studio
5.    Xamarin.Mac (Xamarin Studio)

Why we use Xamarin:

  • Xamarin allows us to code application logic once and then share it across both iOS and Android.
  • Using Xamarin, we only need to learn one language, C#. No need of java (Android) and Objective-C (iOS).
  • The combination of the core .NET classes with the platform-specific classes allow applications to share core logic across both iOS and Android while taking advantage of the each platform's unique features.
  • Readiness for the future
  • Faster time to market
  • One technology stack to code for various platforms










Platforms to develop applications:

We Use Visual Studio for developing the applications. Generally, we use the C# programming language to write the business logic. To create UI we use XAML file.
To develop UI we can also use Xamarin.Forms. Xamarin.Forms code can be shared among android, iOS and windows. For Mac users Xamarin.Studio is the best platform to develop the applications.

Windows       –   Visual Studio
Mac                  –   Xamarin.Studio

PREREQUISITE:
  • ·         One should have a good understanding of code written in C# programming language.
  • ·         One should aware of which programming language used in Android and iOS.
  • ·         Should have good knowledge on android and iOS.
  • ·         Experience in Xamarin platform with .Net coding skills
  • ·         Development experience with C#, Dot Net, SQL Server
  • ·         Experience developing applications (iOS and Android)



How it works:



Xamarin architecture contains

·         UI
·         Business logic
·         Runtime
·         Share the code





What is C#?

C# is pronounced as "C-Sharp". It is an object-oriented programming language provided by Microsoft that runs on .Net Framework. By the help of C# programming language, we can develop different types of secure and robust applications:
  • Window applications
  • Web applications
  • Distributed applications
  • Web service applications
  • Database applications etc.

Xamarin.Forms
Xamarin.Forms is a framework that allows developers to rapidly create cross-platform user interfaces. It provides its own abstraction for the user interface that will be rendered using native controls on iOS, Android, Windows, or Windows Phone. This means that applications can share a large portion of their user interface code and still retain the native look and feel of the target platform. It allows us to use native APIs.





Pros and Cons of Xamarin.Forms:
Pros
  • ·         Create one UI for all platforms
  • ·   Use basic components that are available on all platforms (like Buttons, Textfields, Spinner etc...)
  • ·         No need to learn all the native UI frameworks
  • ·         Fast cross-platform development process
  • ·     Custom native renderers give you the ability to adjust the appearance and feeling of controls

Cons
  • ·         It's still a new framework and still contains bugs
  • ·         Especially Windows RT is not yet stable
  • ·         It's sometimes slower than accessing the native controls directly
  • ·         Custom native renderers have boundaries and are poorly documented
  • ·         Xamarin.Android, Xamarin.iOS, Windows Phone, Windows RT


Xamarin.Forms is best for:
  • ·         Data entry apps
  • ·         Prototypes and proofs-of-concept
  • ·         Apps that require little platform-specific functionality
  • ·         Apps where code sharing is more important than custom UI

Xamarin.iOS & Xamarin.Android are best for:
  • ·         Apps that require specialized interactions
  • ·         Apps with highly polished design
  • ·         Apps that use many platform-specific APIs
  • ·         Apps where custom UI is more important than code sharing


Limitations of Xamarin:
  • ·         Xamarin Studio and Visual Studio are not open sourced.
  • ·         Code developed in Xamarin will not transfer and cannot be reused for native or HTML5 applications for iOS or Android.
  • ·         It's still a new framework and still contains bugs.
  • ·         Xamarin doesn’t come for free.
  • ·         Limited Generics Support.
  • ·         No Dynamic Code Generatio

What did I understand from this research?

Xamarin is a platform to build applications for both the platforms Android and iOS. Mono project which is led by the Xamarin is an open source, we can implement our code. The single C# programming language is needed to learn and we can share the code in both the platforms iOS and Android.

            To build applications in Xamarin we should aware about Xamarin and C# programming language. Also aware about .NET framework. How to code on Visual studio.

Xamarin Studio and Visual Studio are not open sourced. But will be freely available for non-enterprise customers as part of Visual Studio Community and Xamarin Studio Community.