Sunday 21 May 2017

AutocompletetextView

1) activity_main.xml
 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_below="@+id/button"
        android:orientation="vertical" >

        <AutoCompleteTextView
            android:id="@+id/autotxtCategory"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:drawableLeft="@drawable/wildlife"
            android:drawableRight="@drawable/downarro"
            android:ems="10"
            android:hint="@string/category"
            android:imeOptions="actionNext"
            android:singleLine="true"
            android:textColor="@color/white"
            android:textSize="@dimen/edt_text_size" />
    </LinearLayout>

2)auto_list_item
===========
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/val_10"
    android:textSize="@dimen/txt_medium_size"
    android:scrollHorizontally="true"
    android:singleLine="true"
    android:textColor="@color/Black"
    android:text="elk"/>
3)AutoCompleteTextView
===================
package com.example.facebooksharingdemo;

import android.app.Activity;
import android.os.Bundle;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class Autocompletext extends Activity{
private AutoCompleteTextView autoCategory;
private ArrayAdapter<String> aadpCategory;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
autoCategory = (AutoCompleteTextView) findViewById(R.id.autotxtCategory);
aadpCategory = new ArrayAdapter<String>(this, R.layout.auto_list_item, alstCatName);
autoCategory.setAdapter(aadpCategory);

autoCategory.setThreshold(1);

autoCategory.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
autoCategory.showDropDown();
}
});

autoCategory.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
intCatId = alstCatId.get(position);
System.out.println("intCatId:::Selected::::****==" + intCatId);
GetSubCategoryData(intCatId);
}
});
}

}

Notification bedge count drawable

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="@android:color/black" />

    <padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp" />

    <corners
        android:bottomLeftRadius="15dp"
        android:bottomRightRadius="15dp"
        android:topLeftRadius="15dp"
        android:topRightRadius="15dp" />

</shape>

Wednesday 17 May 2017

Youtube video play

1) YoutubeVideoPlay.java
==================
package com.activities;

import android.os.Bundle;

import com.R;
import com.utils.StaticUtils;
import com.utils.YouTubeFailureRecoveryActivity;
import com.google.android.youtube.player.YouTubeInitializationResult;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;

public class YoutubeVideoPlay extends YouTubeFailureRecoveryActivity implements YouTubePlayer.OnInitializedListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_youtube_video_play);

        YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
        youTubeView.initialize(StaticUtils.DEVELOPER_KEY, this);
    }

    @Override
    public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer youTubePlayer, boolean wasRestored) {
        if (!wasRestored) {
            youTubePlayer.cueVideo(PostDetail.VIDEO_URL);
            youTubePlayer.setFullscreen(true);
            youTubePlayer.setShowFullscreenButton(false);
        }
    }

    @Override
    public void onInitializationFailure(YouTubePlayer.Provider provider, YouTubeInitializationResult youTubeInitializationResult) {

    }

    @Override
    protected YouTubePlayer.Provider getYouTubePlayerProvider() {
        return (YouTubePlayerView) findViewById(R.id.youtube_view);
    }
}

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

    <com.google.android.youtube.player.YouTubePlayerView
        android:id="@+id/youtube_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

3) app=>libs add
   YouTubeAndroidPlayerApi.jar

4)Intent i = new Intent(PostDetail.this, YoutubeVideoPlay.class);
                                startActivity(i);

5) add internet permission
6)  public static final String DEVELOPER_KEY = "AIzaSyA4umjr-_ev7AT1IfCnzidGNk2BkDkH898";
7)refer android hive for more detail

Saturday 13 May 2017

EventBus Demo

1) ChildActivity.java

package eventbusdemo.credencys.com.eventbusdemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import org.greenrobot.eventbus.EventBus;

public class ChildActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText messageEditText;
    private Button triggerEventButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_child);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        messageEditText = (EditText) findViewById(R.id.activity_child_edt_message);
        triggerEventButton = (Button) findViewById(R.id.activity_child_btn_trigger);

        triggerEventButton.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.activity_child_btn_trigger:
                String message = messageEditText.getText().toString().trim();

                CustomMessageEvent event = new CustomMessageEvent();
                event.setCustomMsg(message);
                EventBus.getDefault().post(event);
                finish();
                break;
        }
    }
}


2)CustomMessageEvent  .java
package eventbusdemo.credencys.com.eventbusdemo;

/**
 * Created by manisha on 20/2/17.
 */

public class CustomMessageEvent  {

    public String customMsg;

    public String getCustomMsg() {
        return customMsg;
    }

    public void setCustomMsg(String customMsg) {
        this.customMsg = customMsg;
    }
}

3)MainActivity .java
package eventbusdemo.credencys.com.eventbusdemo;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private EditText resultsEditText;
    private Button launchButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        resultsEditText = (EditText)findViewById(R.id.activity_main_edt_result);
        launchButton = (Button)findViewById(R.id.activity_main_btn_launch);

        launchButton.setOnClickListener(this);
        EventBus.getDefault().register(this);
    }

    @Subscribe
    public void onEvent(CustomMessageEvent event){
        Log.e("","Event bus::"+event.getCustomMsg());
        resultsEditText.setText(event.getCustomMsg());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.activity_main_btn_launch:
                Intent intent = new Intent(MainActivity.this,ChildActivity.class);
                startActivity(intent);
                break;
        }
    }
}


Gradle
apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "eventbusdemo.credencys.com.eventbusdemo"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile 'com.android.support:appcompat-v7:25.1.0'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.android.support:design:25.1.0'
    testCompile 'junit:junit:4.12'
}
 

Thursday 11 May 2017

broadcast receiver

onresume:
        LocalBroadcastManager.getInstance(HomeScreen.this).registerReceiver(receiver, new IntentFilter(BROADCAST_ACTION));

 public static final String BROADCAST_ACTION = "NotifyInbox";
    private BroadcastReceiver receiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            boolean notify = intent.getBooleanExtra("notify_count", false);
            Log.e("notify_count ", "" + notify);
            if (notify) {
                mAdapterMenu.notifyDataSetChanged();
            }
        }
    };

LocalBroadcastManager.getInstance(HomeScreen.this).unregisterReceiver(receiver);

Monday 8 May 2017

Social sharing via intent



***
import android.net.Uri;

http://stackoverflow.com/questions/7545254/android-and-facebook-share-intent

http://stackoverflow.com/questions/3515198/share-text-on-facebook-from-android-app-via-action-send

          SocialSharing("com.facebook.katana");

void SocialSharing(String packageName) {
        final boolean isInstalled = appInstalledOrNot(packageName);
        if (isInstalled) {
            Intent waIntent = new Intent(Intent.ACTION_SEND);
            waIntent.setType("text/plain");
            waIntent.setPackage(packageName);
            if (waIntent != null) {
                if (!personalMsg.equalsIgnoreCase("")) {
                    //waIntent.putExtra(Intent.EXTRA_TEXT, "Hi");
                    waIntent.putExtra(Intent.EXTRA_TEXT, personalMsg + " \n \n" + getResources().getString(R.string.share_text) + " " + AppPrefs.getInstance(mContext).getOrgName().toString().toLowerCase() + " \n\n" + mShortURL);
                } else {
                    waIntent.putExtra(Intent.EXTRA_TEXT, mShortURL + " \n\n" + getResources().getString(R.string.share_text) + AppPrefs.getInstance(mContext).getOrgName().toString().toLowerCase());
                }
                startActivity(Intent.createChooser(waIntent, "share with"));
            }
        } else {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("market://details?id=" + packageName));
            startActivity(intent);
        }
    }

    private boolean appInstalledOrNot(String uri) {
        PackageManager pm = getPackageManager();
        boolean app_installed;
        try {
            pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
            app_installed = true;
        } catch (PackageManager.NameNotFoundException e) {
            app_installed = false;
        }
        return app_installed;
    }