Wednesday, November 12, 2014

android headset or headphone button controller

download:   http://www.mediafire.com/download/0667cfia4yo0yig/HeadsetControll.zip

package com.headset;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.os.Bundle;
import android.util.Log;

public class AudioEqualizerActivity extends Activity {

    // Using LinearLayout instead of R.layout.main (main.xml)
    BroadcastReceiver broadcastsHandler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        IntentFilter filter = new IntentFilter(Intent.ACTION_MEDIA_BUTTON);// "android.intent.action.MEDIA_BUTTON"
        MediaButtonReceiver r = new MediaButtonReceiver();
        filter.setPriority(100);
        registerReceiver(r, filter);

        // unregisterReceiver(broadcastsHandler);

        Log.e("----onCreate--", " ");

    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

        broadcastsHandler = new MediaButtonReceiver();

        registerReceiver(broadcastsHandler, new IntentFilter(
                Intent.ACTION_HEADSET_PLUG));

        registerMediaButton(AudioEqualizerActivity.this);
    }

    public static void registerMediaButton(Context context) {

        AudioManager audioManager = (AudioManager) context
                .getSystemService(Context.AUDIO_SERVICE);
        ComponentName receiver = new ComponentName(context.getPackageName(),
                MediaButtonReceiver.class.getName());
        audioManager.registerMediaButtonEventReceiver(receiver);
    }

    /**
     * Unregister the media buttons from AudioManager.
     *
     * @param context
     *            A context to use.
     */
    public static void unregisterMediaButton(Context context) {
        AudioManager audioManager = (AudioManager) context
                .getSystemService(Context.AUDIO_SERVICE);
        ComponentName receiver = new ComponentName(context.getPackageName(),
                MediaButtonReceiver.class.getName());
        audioManager.unregisterMediaButtonEventReceiver(receiver);
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();

        unregisterReceiver(broadcastsHandler);
        unregisterMediaButton(AudioEqualizerActivity.this);

    }

    @Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();

        unregisterReceiver(broadcastsHandler);
        unregisterMediaButton(AudioEqualizerActivity.this);

    }
}




package com.headset;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

public class MediaButtonReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e("----onReceive--", " ");

        if (Intent.ACTION_HEADSET_PLUG.equals(intent.getAction())) {
           
            Log.e("----jack out--", " ");

            if (intent.getExtras().getInt("state") == 1)// if plugged
                Toast.makeText(context, "earphones plugged", Toast.LENGTH_LONG)
                        .show();
            else
                Toast.makeText(context, "earphones un-plugged",
                        Toast.LENGTH_LONG).show();
        }

        if (Intent.ACTION_MEDIA_BUTTON.equals(intent.getAction())) {
            Toast.makeText(context, "button pressed", Toast.LENGTH_LONG).show();
            // key=intent.getExtras().getString("EXTRA_KEY_EVENT");

        }
       
        abortBroadcast();

    }
}



mainifest
------------------------

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.headset"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="9" />

    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <!-- This is needed for isWiredHeadsetOn() to work in some cases. (bug?) -->
    <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".AudioEqualizerActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name="com.headset.MediaButtonReceiver" >
            <intent-filter android:priority="10" >
                <action android:name="android.intent.action.MEDIA_BUTTON" />
            </intent-filter>
            <intent-filter android:priority="20" >
                <action android:name="android.intent.action.HEADSET_PLUG" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

Monday, August 11, 2014

custom notification

download: http://www.mediafire.com/download/1nis9ose1xs13u2/NotificationCustom.zip




package com.mirtech.mirtube;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RemoteViews;

public class SplashActivity extends Activity {

Context context;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

context = SplashActivity.this;

RemoteViews remoteViews = new RemoteViews(getPackageName(),
R.layout.splash);

remoteViews.setTextViewText(R.id.textView1, "ssssssss");

// When we click the widget, we want to open our main activity.
Intent defineIntent2 = new Intent(context, MyBroadcastReceiver.class);
PendingIntent pendingIntent2 = PendingIntent.getBroadcast(context,
0 /* no requestCode */, defineIntent2, 0 /* no flags */);
remoteViews.setOnClickPendingIntent(R.id.button1, pendingIntent2);


Notification.Builder mBuilder = new Notification.Builder(this)
.setSmallIcon(R.drawable.ic_launcher).setContent(remoteViews);

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(100, mBuilder.build());




}

}









package com.mirtech.mirtube;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class MyBroadcastReceiver extends BroadcastReceiver {

@Override 
 public void onReceive(Context _context, Intent _intent) {
Log.e("-----onReceive", " ");
//    if (_intent.getAction().equals("hi")) {
//      // TODO Broadcast a notification
//      
//    }
 }    

}




<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mirtech.mirtube"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />

    <uses-permission android:name="android.permission.RECORD_VIDEO" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.mirtech.mirtube.SplashActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <receiver android:name="MyBroadcastReceiver" >
            <intent-filter>
                <action android:name="hi" />
            </intent-filter>
        </receiver>
    </application>

</manifest>

Wednesday, February 19, 2014

View Switcher example

view flipper

download:  http://www.mediafire.com/download/7j0ycdg5j2mdpvy/ViewFlipperDemos.zip



package com.ui.yogeshblogspot;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ViewFlipper;

public class Main extends Activity {

ViewFlipper flipper;
Button btBackPage;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Getting View Flipper from main.xml and assigning to flipper reference
// variable
flipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
btBackPage = (Button) findViewById(R.id.btBackPage);

btBackPage.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v)
{
if (flipper.isFlipping())// Checking flipper is flipping or not.
{
flipper.stopFlipping(); // stops the flipping .
}
flipper.showPrevious();// shows the next view element of ViewFlipper
}
});
}

public void flipByClick(View v) {
if (flipper.isFlipping())// Checking flipper is flipping or not.
{
flipper.stopFlipping(); // stops the flipping .
}
flipper.showNext();// shows the next view element of ViewFlipper
}

public void flipByInterval(View v) {
flipper.setFlipInterval(500);// setting the interval 500 milliseconds
flipper.startFlipping(); // views flipping starts.
}
}


--------------------------------
main.xml
----------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >
        <!-- Calling flipByInterval() method of Activity class -->
       
         <Button
            android:id="@+id/btBackPage"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
             android:layout_weight="0.40"
            android:text="Back Flip"
            android:background="@android:color/holo_green_dark"/>

        <Button
            android:id="@+id/flipbyclick"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_weight="0.40"
            android:background="@android:color/holo_green_dark"
            android:onClick="flipByClick"
            android:layout_marginLeft="10dp"
            android:text="Flip By Click" />

        <!-- calling flipByClick() method of Activity class -->
    </LinearLayout>
    <!-- ViewFlipper can contains any view elements in this case it contains 5 ImageView view Component with different Images -->

    <ViewFlipper
        android:id="@+id/viewFlipper1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <include
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            layout="@layout/dialog_text" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img1" />
        <!-- Setting img1 from drawable folder in ImageView -->

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img2" />
        <!-- Setting img2 from drawable folder in ImageView -->

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img3" />
        <!-- Setting img3 from drawable folder in ImageView -->

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img4" />
        <!-- Setting img4 from drawable folder in ImageView -->

        <ImageView
            android:id="@+id/imageView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img5" />
        <!-- Setting img5 from drawable folder in ImageView -->

        <ImageView
            android:id="@+id/imageView6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/img6" />
        <!-- Setting img6 from drawable folder in ImageView -->

       

    </ViewFlipper>
   
 
   
    <Button
            android:id="@+id/flipbyinterval"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="0.25"
            android:onClick="flipByInterval"
            android:text="Flip By Interval" />

</LinearLayout>



--------------------------------
dialog_text.xml
--------------------------------
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight=".50" >

        <Button
            android:id="@+id/imageViewSearchBanner"
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:text="new btn" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight=".50" >

        <Button
            android:id="@+id/ivForText"
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:text="other btn" />
    </LinearLayout>

</LinearLayout>