import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class SharePost extends Activity implements OnClickListener {
private Intent intent;
private ImageView hide_location, annonymous_post, share_post, post,video_thumb_img_v;
private LinearLayout share_post_video_thumnail_v_layout;
private EditText comments;
public static boolean isShowImageView, isShowVideoView,isShowGalleryView;
private LinearLayout fb_icon, twtricon, tumblricon, mailicon,hide_location_ly,anonymous_post_ly;
private SharePost activity = this;
private ApiServices api = new ApiServices();
private String comment = " ", key = "text";
private Bitmap img_bm;
Bitmap bitmap;
public static Bitmap video_thumb=null;
// used for move menu left and right
private RelativeLayout navigation_menu_in_rel_ly;
public static File imgFile;
public static String path;
Uri uriimagepathcrop;
Button btn;
//used for navigation
private ImageView camera_menu, profile_menu, setting_menu, search_menu,
moveBack, notification_menu, moveOver;
//private Intent intent;
private String TAG = "SharePost";
private DBController db = new DBController(activity);
String img_url,video_url,crop_url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.sharepost);
doInitView();
doSetNavigationMenu(true, navigation_menu_in_rel_ly);
hideShowImageView();
doSettings();
}
@Override
public void onBackPressed() {
}
/***************** intilize view ********************/
private void doInitView() {
share_post = (ImageView) findViewById(R.id.share_post_img_v);
post = (ImageView) findViewById(R.id.post_comments_img_v);
comments = (EditText) findViewById(R.id.share_post_commt_edt);
share_post_video_thumnail_v_layout=(LinearLayout)findViewById(R.id.share_post_video_thumnail_v_lay);
video_thumb_img_v = (ImageView) findViewById(R.id.share_post_video_thumnail_v);
video_thumb_img_v.setOnClickListener(activity);
navigation_menu_in_rel_ly = (RelativeLayout) findViewById(R.id.sharepost_navigation_menu_relative_lay);
//me
btn=(Button) findViewById(R.id.btn);
btn.setOnClickListener(this);
//navigation_menu_in_rel_ly.setOnClickListener(this);
hide_location = (ImageView) findViewById(R.id.hide_location_img);
annonymous_post = (ImageView) findViewById(R.id.annonymous_post_img_v);
fb_icon = (LinearLayout) findViewById(R.id.facebook_icon);
twtricon = (LinearLayout) findViewById(R.id.twitter_icon);
tumblricon = (LinearLayout) findViewById(R.id.instagram_icon);
mailicon = (LinearLayout) findViewById(R.id.mail_icon);
hide_location_ly= (LinearLayout) findViewById(R.id.hide_location_lay);
anonymous_post_ly=(LinearLayout)findViewById(R.id.anonymous_post_lay);
hide_location.setOnClickListener(activity);
annonymous_post.setOnClickListener(activity);
fb_icon.setOnClickListener(activity);
twtricon.setOnClickListener(activity);
tumblricon.setOnClickListener(activity);
mailicon.setOnClickListener(activity);
post.setOnClickListener(activity);
hide_location.setOnClickListener(activity);
annonymous_post.setOnClickListener(activity);
//used for navigation
moveOver = (ImageView) findViewById(R.id.home_menu_cantrol_img_v);
camera_menu = (ImageView) findViewById(R.id.home_camera_menu_img_v);
profile_menu = (ImageView) findViewById(R.id.home_profile_menu_img_v);
setting_menu = (ImageView) findViewById(R.id.home_setting_menu_img_v);
notification_menu = (ImageView) findViewById(R.id.home_notification_menu_img_v);
search_menu = (ImageView) findViewById(R.id.home_search_menu_img_v);
moveBack = (ImageView) findViewById(R.id.home_back_menu_img_v);
moveOver.setOnClickListener(this);
camera_menu.setOnClickListener(this);
profile_menu.setOnClickListener(this);
setting_menu.setOnClickListener(this);
notification_menu.setOnClickListener(this);
search_menu.setOnClickListener(this);
moveBack.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.facebook_icon:
sharePostToSites("com.facebook.katana","Facebook");
break;
case R.id.instagram_icon:
sharePostToSites("com.instagram.android","Instagram");
break;
case R.id.twitter_icon:
sharePostToSites("com.twitter.android","Twitter");
break;
case R.id.mail_icon:
sharePostToSites("com.google.android.gm","Gmail");
break;
case R.id.hide_location_img:
doHideLocationSettings();
break;
case R.id.annonymous_post_img_v:
doAnonyomousSettings();
break;
case R.id.share_post_video_thumnail_v:
//play video from video sdcard url
try {
String url= Common.getPostCommentsVideoUrl(activity);
Common.printLog("---url is ---", "-"+url);
if(Build.VERSION.SDK_INT<19)
{
intent =new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(Common.getPostCommentsVideoUrl(activity)), "video/*");
startActivity(intent);
}
else
{
//used for kitkat and above
Uri uri=Uri.fromFile(new File(url));
intent =new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");
startActivity(intent);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case R.id.post_comments_img_v:
if (!Common.getPostCommentsImageUrl(activity).equals("0")) {
key = "image";
} else if (!Common.getPostCommentsVideoUrl(activity).equals("0")) {
key = "video";
}else if(isShowGalleryView){
key = "image";
} else {
key = "text";
}
getInputValue();
/*if (comment.length() > 0)
{
*/
if (Common.isInternetOn(activity)) {
// new uploadvideo().execute();
if(PostemicService.latitude>4 && PostemicService.longitude>4)
{
if(Camera_.booli==true){
Log.i("In","booli if");
api.doPostComment(activity, Common.getUserId(activity),
Common.getAnonymoutPost(activity),
Common.getHideLocation(activity), key, comment,
PostemicService.latitude,PostemicService.longitude,video_thumb);
}else{
api.doPostComment(activity, Common.getUserId(activity),
Common.getAnonymoutPost(activity),
Common.getHideLocation(activity), key, comment,
PostemicService.latitude,PostemicService.longitude,bitmap);
}
/*api.doPostComment(activity, Common.getUserId(activity),
Common.getAnonymoutPost(activity),
Common.getHideLocation(activity), key, comment,
PostemicService.latitude,PostemicService.longitude,bitmap);*/
}else {
Common.showToast(activity, "Your location doesn't find !", Toast.LENGTH_SHORT);
}
} else {
Common.showToast(activity,
getString(R.string.network_unavailable),
Toast.LENGTH_SHORT);
}
/* }
else
{
Common.showToast(activity, "Comments field is required",Toast.LENGTH_SHORT);
}*/
break;
case R.id.home_menu_cantrol_img_v:
onHomeClickForMoveOver();
btn.setVisibility(View.VISIBLE);
//me
// navigation_menu_in_rel_ly.setVisibility(View.VISIBLE);
//finish();
break;
case R.id.home_camera_menu_img_v:
intent = new Intent(activity, Camera_.class);
startActivity(intent);
finish();
break;
case R.id.home_profile_menu_img_v:
if(Common.isInternetOn(activity)){
api.doGetProfilePostComments(activity, Common.getUserId(activity),"me");
}else{
Common.showToast(activity, getString(R.string.network_unavailable), Toast.LENGTH_SHORT);
}
break;
case R.id.home_setting_menu_img_v:
//used only for postemic points
if (Common.isInternetOn(activity)) {
api.doGetPostemicPoint(activity,Common.getUserId(activity),"me");
} else {
Common.showToast(activity,getString(R.string.network_unavailable),Toast.LENGTH_SHORT);
}
break;
case R.id.home_notification_menu_img_v:
// get notif_list from db and save in notif list in api services
boolean notif_is_exist = db.getAllNotification();
Common.printLog(TAG, " notif is exist " + notif_is_exist);
intent = new Intent(activity, Notification_.class);
startActivity(intent);
finish();
break;
case R.id.home_search_menu_img_v:
// call api of getappuser list
if (Common.isInternetOn(activity)) {
api.doGetAllAppUser(activity);
} else {
Common.showToast(activity,
getString(R.string.network_unavailable),
Toast.LENGTH_SHORT);
}
break;
case R.id.home_back_menu_img_v:
onBackClickMoveBack();
btn.setVisibility(View.GONE);
api.doGetComments1(activity, Common.getUserId(activity));
break;
case R.id.btn:
onBackClickMoveBack();
btn.setVisibility(View.GONE);
break;
/*//me
case R.id.home_navigation_menu_relative_lay:
onBackClickMoveBack();
break;*/
}
}
/**************** get input value from edit text **********************/
private void getInputValue() {
comment = comments.getText().toString().trim();
}
/****************** Facebook icon click click listener ******************/
private void onFacebookIconClick() {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Text...");
PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(
sharingIntent, PackageManager.MATCH_DEFAULT_ONLY);
Log.d("app", resolvedInfoList.toString());
boolean resolved = false;
for (ResolveInfo resolveInfo : resolvedInfoList) {
if (resolveInfo.activityInfo.packageName
.startsWith("com.facebook.katana")) {
sharingIntent.setClassName(
resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name);
resolved = true;
break;
}
}
if (resolved) {
startActivity(sharingIntent);
} else {
Builder alert = new AlertDialog.Builder(SharePost.this);
alert.setTitle("Warning");
alert.setMessage("Facebook App not found");
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
}
/************** on twitter icon click listener ***************/
private void onTwitterIconClick() {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Text...");
PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(
sharingIntent, PackageManager.MATCH_DEFAULT_ONLY);
boolean resolved = false;
for (final ResolveInfo app : resolvedInfoList)
{
if ("com.twitter.android.PostActivity".equals(app.activityInfo.name))
{
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
activity.applicationInfo.packageName, activity.name);
sharingIntent.addCategory(Intent.CATEGORY_LAUNCHER);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
sharingIntent.setComponent(name);
resolved = true;
break;
}
}
if (resolved) {
startActivity(sharingIntent);
} else {
Builder alert = new AlertDialog.Builder(SharePost.this);
alert.setTitle("Warning");
alert.setMessage("Twitter App not found");
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
}
/**************** on mail icon click ****************/
private void onMailIconClick() {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Text...");
PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(
sharingIntent, PackageManager.MATCH_DEFAULT_ONLY);
Log.d("app", resolvedInfoList.toString());
boolean resolved = false;
for (final ResolveInfo app : resolvedInfoList) {
Log.d("app", app.activityInfo.name);
if ((app.activityInfo.name).startsWith("com.google.android.gm")) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
activity.applicationInfo.packageName, activity.name);
sharingIntent.addCategory(Intent.CATEGORY_LAUNCHER);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
sharingIntent.setComponent(name);
resolved = true;
break;
}
}
if (resolved) {
startActivity(sharingIntent);
} else {
Builder alert = new AlertDialog.Builder(SharePost.this);
alert.setTitle("Warning");
alert.setMessage("Gmail App not found");
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
}
/************ hide and show image view for post ***********/
private void hideShowImageView()
{
if (isShowImageView)
{
Log.d("in share post", "in share post");
share_post.setVisibility(View.VISIBLE);
share_post_video_thumnail_v_layout.setVisibility(View.GONE);
imgFile = new File(Common.getPostCommentsImageUrl(activity));
img_url="img";
video_url="";
crop_url="";
/*Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
if(bitmap != null)
{
share_post.setImageBitmap(bitmap);
}*/
//Toast.makeText(getApplicationContext(), "img path: "+imgFile.toString(), Toast.LENGTH_SHORT).show();
Intent intent = getIntent();
path = intent.getStringExtra("path");
if(imgFile.exists())
{
img_bm = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
if (img_bm != null)
{
String path = imgFile.getAbsolutePath();
Uri uri = Uri.parse(path);
share_post.setImageBitmap(img_bm);
}
}
} else {
Common.setPostCommentsImageUrl(activity, "0");
}
if (isShowVideoView) {
share_post.setVisibility(View.GONE);
share_post_video_thumnail_v_layout.setVisibility(View.VISIBLE);
imgFile = new File(Common.getPostCommentsVideoUrl(activity));
/*img_url="";
video_url="video";*/
img_url="";
video_url="vid";
crop_url="";
//Toast.makeText(getApplicationContext(), "vdo path: "+imgFile.toString(), Toast.LENGTH_SHORT).show();
if (Common.getPostCommentsVideoUrl(activity).length()>5) {
video_thumb=Common.getThumbnailFromVideo(activity, Common.getPostCommentsVideoUrl(activity));
share_post_video_thumnail_v_layout.setBackgroundDrawable(Common.getDrawableFromBitmap(activity, video_thumb));
}
} else {
Common.setPostCommentsVideoUrl(activity, "0");
}
if (isShowGalleryView) {
share_post.setVisibility(View.VISIBLE);
imgFile=new File(Common.getPostCommentGalleryImage(activity));
/*img_url="imgcrop";
video_url="vdocrop";*/
img_url="";
video_url="";
crop_url="crop";
if (!Common.getPostCommentGalleryImage(activity).equals("0")) {
if(Camera_.booli==true){
Log.i("in","share if");
//Toast.makeText(activity, "In Share If", Toast.LENGTH_SHORT).show();
share_post.setImageBitmap(Common.StringToBitMap(Common.getPostCommentGalleryImage(activity)));
Bitmap bm=Common.StringToBitMap(Common.getPostCommentGalleryImage(activity));
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
img_url= Images.Media.insertImage(getContentResolver(), bm, "title", null);
SharedPreferences sharedpreferences = getApplicationContext().getSharedPreferences("shareData", Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();
editor.putString("delete", img_url);
editor.commit();
Log.i("URLLL",""+img_url);
uriimagepathcrop=Uri.parse(img_url);
}else{
//Toast.makeText(activity, "In Share else", Toast.LENGTH_SHORT).show();
Log.i("in","share else");
Intent intent = getIntent();
bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
path = intent.getStringExtra("path");
img_url=intent.getStringExtra("path");
SharedPreferences sharedpreferences = getApplicationContext().getSharedPreferences("shareData", Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();
editor.putString("delete", path);
editor.commit();
uriimagepathcrop=Uri.parse(img_url);
Log.i("Path",""+path);
}
/*share_post.setImageBitmap(Common.StringToBitMap(Common.getPostCommentGalleryImage(activity)));
Bitmap bm=Common.StringToBitMap(Common.getPostCommentGalleryImage(activity));
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
img_url= Images.Media.insertImage(getContentResolver(), bm, "title", null);
Log.i("URLLL",""+img_url);
uriimagepathcrop=Uri.parse(img_url);
//share_post.setImageBitmap(bm);
*/
/*ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path_ = Images.Media.insertImage(getContentResolver(), bitmap, "Title", null);
//
Log.i("FI","c"+path);
*/
}
}else {
Common.setPostCommentGalleryImage(activity, "0");
}
if(!isShowVideoView && !isShowGalleryView && !isShowImageView)
{
img_url="";
video_url="";
crop_url="";
}
}
/************ hide and show image view for post ***********/
/*private void hideShowImageView()
{
if (isShowImageView)
{
Log.d("in share post", "in share post");
share_post.setVisibility(View.VISIBLE);
share_post_video_thumnail_v_layout.setVisibility(View.GONE);
File imgFile = new File(Common.getPostCommentsImageUrl(activity));
Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
if(bitmap != null)
{
share_post.setImageBitmap(bitmap);
}
if(imgFile.exists())
{
img_bm = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
if (img_bm != null)
{
share_post.setImageBitmap(img_bm);
}
}
} else {
Common.setPostCommentsImageUrl(activity, "0");
}
if (isShowVideoView) {
share_post.setVisibility(View.GONE);
share_post_video_thumnail_v_layout.setVisibility(View.VISIBLE);
if (Common.getPostCommentsVideoUrl(activity).length()>5) {
video_thumb=Common.getThumbnailFromVideo(activity, Common.getPostCommentsVideoUrl(activity));
share_post_video_thumnail_v_layout.setBackgroundDrawable(Common.getDrawableFromBitmap(activity, video_thumb));
}
} else {
Common.setPostCommentsVideoUrl(activity, "0");
}
if (isShowGalleryView) {
share_post.setVisibility(View.VISIBLE);
if (!Common.getPostCommentGalleryImage(activity).equals("0")) {
share_post.setImageBitmap(Common.StringToBitMap(Common.getPostCommentGalleryImage(activity)));
}
}else {
Common.setPostCommentGalleryImage(activity, "0");
}
}
*/
/************ set setting status ***********/
private void doSettings() {
if (Common.getHideLocation(activity).equals("0")) {
hide_location.setImageResource(R.drawable.worng);
hide_location_ly.setBackgroundColor(getResources().getColor(R.color.gray));
} else {
hide_location.setImageResource(R.drawable.rightbutton);
hide_location_ly.setBackgroundColor(getResources().getColor(R.color.app_backgroud_color));
}
if (Common.getAnonymoutPost(activity).equals("0")) {
annonymous_post.setImageResource(R.drawable.worng);
anonymous_post_ly.setBackgroundColor(getResources().getColor(R.color.gray));
} else {
annonymous_post.setImageResource(R.drawable.rightbutton);
anonymous_post_ly.setBackgroundColor(getResources().getColor(R.color.app_backgroud_color));
}
}
/************ manage hide locaion setting ***********/
private void doHideLocationSettings() {
if (Common.getHideLocation(activity).equals("0")) {
hide_location.setImageResource(R.drawable.rightbutton);
Common.setHideLocation(activity, "1");
hide_location_ly.setBackgroundColor(getResources().getColor(R.color.app_backgroud_color));
} else {
hide_location.setImageResource(R.drawable.worng);
Common.setHideLocation(activity, "0");
hide_location_ly.setBackgroundColor(getResources().getColor(R.color.gray));
}
}
/************ manage anonyomous setting ***********/
private void doAnonyomousSettings() {
if (Common.getAnonymoutPost(activity).equals("0")) {
annonymous_post.setImageResource(R.drawable.rightbutton);
Common.setAnonymoutPost(activity, "1");
anonymous_post_ly.setBackgroundColor(getResources().getColor(R.color.app_backgroud_color));
} else {
annonymous_post.setImageResource(R.drawable.worng);
Common.setAnonymoutPost(activity, "0");
anonymous_post_ly.setBackgroundColor(getResources().getColor(R.color.gray));
}
}
/****** set navigation menu in left and right *******/
private void doSetNavigationMenu(boolean in_left, RelativeLayout nav_lay) {
if (in_left) {
nav_lay.setGravity(Gravity.LEFT);
} else {
nav_lay.setGravity(Gravity.RIGHT);
}
}
/************ on postemic home click for move over *************/
private void onHomeClickForMoveOver() {
// comment bcos menu show only left side
// if (Common.getPostemicMenu(activity).equals("0")) {
if (Common.getDeviceDensityName(activity).equals("ldpi")) {
Common.doAmimatonFromLeft(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getLeft(), moveBack);
} else if (Common.getDeviceDensityName(activity).equals("mdpi")) {
Common.doAmimatonFromLeft(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getLeft(), moveBack);
} else if (Common.getDeviceDensityName(activity).equals("hdpi")) {
Common.doAmimatonFromLeft(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getLeft(), moveBack);
}
//me
else if (Common.getDeviceDensityName(activity).equals("xxhdpi")) {
Common.doAmimatonFromLeftXXhdpi(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getLeft(), moveBack);
}
else if (Common.getDeviceDensityName(activity).equals("xxxhdpi")) {
Common.doAmimatonFromLeftXXXhdpi(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getLeft(), moveBack);
}
//
else {
Common.doAmimatonFromLeftForXhdpi(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
}
/*
} else if (Common.getPostemicMenu(activity).equals("1")) {
if (Common.getDeviceDensityName(activity).equals("ldpi")) {
Common.doAmimatonFromRight(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getRight(), moveBack);
} else if (Common.getDeviceDensityName(activity).equals("mdpi")) {
Common.doAmimatonFromRight(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getRight(), moveBack);
} else if (Common.getDeviceDensityName(activity).equals("hdpi")) {
Common.doAmimatonFromRight(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getRight(), moveBack);
} else {
Common.doAmimatonFromRightForXhdpi(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getRight(),
moveBack);
}
}
*/
}
/************ on postemic back click for back from over *************/
private void onBackClickMoveBack() {
// if (Common.getPostemicMenu(activity).equals("0")) {
if (Common.getDeviceDensityName(activity).equals("ldpi")) {
Common.doResetAmimatonFromLeft(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
} else if (Common.getDeviceDensityName(activity).equals("mdpi")) {
Common.doResetAmimatonFromLeft(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
} else if (Common.getDeviceDensityName(activity).equals("hdpi")) {
Common.doResetAmimatonFromLeft(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
}
//me
else if (Common.getDeviceDensityName(activity).equals("xxhdpi")) {
Common.doResetAmimatonFromLeftXXhdpi(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
}
else if (Common.getDeviceDensityName(activity).equals("xxxhdpi")) {
Common.doResetAmimatonFromLeftXXXhdpi(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
}
//
else {
Common.doResetAmimatonFromLeftForXhdpi(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
}
/*
} else if (Common.getPostemicMenu(activity).equals("1")) {
if (Common.getDeviceDensityName(activity).equals("ldpi")) {
Common.doResetAmimatonFromRight(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getRight(),
moveBack);
} else if (Common.getDeviceDensityName(activity).equals("mdpi")) {
Common.doResetAmimatonFromRight(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getRight(),
moveBack);
} else if (Common.getDeviceDensityName(activity).equals("hdpi")) {
Common.doResetAmimatonFromRight(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getRight(),
moveBack);
} else {
Common.doResetAmimatonFromRightForXhdpi(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getRight(),
moveBack);
}
}
*/
}
// by pradeep
private void sharePostToSites(String pak, String file) {
// TODO Auto-generated method stub
try{
if(packageInstalledOrNot(pak))
{
getInputValue();
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
if (img_url.length()!=0 || crop_url.length()!=0)
{
Uri uri = Uri.fromFile(imgFile);
Log.d("UriPath: ", "" + uri);
sharingIntent.setType("image/*");
if(img_url.length()>0)
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
else
sharingIntent.putExtra(Intent.EXTRA_STREAM, uriimagepathcrop);
sharingIntent.putExtra(Intent.EXTRA_TEXT, comment);
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sharingIntent.setPackage(pak);
startActivity(sharingIntent);
}
else if (video_url.length()!=0)
{
if(!file.equalsIgnoreCase("Twitter"))
{
Uri uri = Uri.fromFile(imgFile);
Log.d("UriPath: ", "" + uri);
sharingIntent.setType("video/*");
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.putExtra(Intent.EXTRA_TEXT, comment);
sharingIntent.setPackage(pak);
startActivity(sharingIntent);
}
else
{
Toast toast=Toast.makeText(getApplicationContext(), "Video not uplaoded to Twitter", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
else
{
/*sharingIntent.setType("text/plain");
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sharingIntent.putExtra(Intent.EXTRA_TEXT, comment);
sharingIntent.setPackage(pak);
startActivity(sharingIntent);*/
if(!(file.equalsIgnoreCase("facebook") || file.equalsIgnoreCase("Instagram")))
{
sharingIntent.setType("text/plain");
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sharingIntent.putExtra(Intent.EXTRA_TEXT, comment);
sharingIntent.setPackage(pak);
startActivity(sharingIntent);
}
else
{
Toast.makeText(getApplicationContext(), "Text not uploaded to "+file, Toast.LENGTH_SHORT).show();
}
}
}
else
{
Toast.makeText(activity, file+" not found in your device", Toast.LENGTH_SHORT).show();
}
}
catch(Exception e)
{
e.printStackTrace();
}
/* try{
if(packageInstalledOrNot(pak))
{
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Postemic");
if (img_url.length()>0 && img_url.length()<4)
{
Uri uri = Uri.fromFile(imgFile);
Log.d("UriPath: ", "" + uri);
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "" + "your message \n\n\n www.postemic.com");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "" + "Postemic Data");
sharingIntent.putExtra(Intent.EXTRA_TITLE, "" + "www.postemic.com");
sharingIntent.setPackage(pak);
startActivity(sharingIntent);
}
else if (video_url.length()>0 && video_url.length()<4)
{
if(!file.equalsIgnoreCase("Twitter"))
{
Uri uri = Uri.fromFile(imgFile);
Log.d("UriPath: ", "" + uri);
sharingIntent.setType("video/*");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "" + "your message \n\n\n www.postemic.com");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "" + "Postemic Data");
sharingIntent.putExtra(Intent.EXTRA_TITLE, "" + "www.postemic.com");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.setPackage(pak);
startActivity(sharingIntent);
}
else
{
Toast toast=Toast.makeText(getApplicationContext(), "Video not uplaoded to Twitter", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
else
{
//Toast.makeText(getApplicationContext(), img_url, Toast.LENGTH_LONG).show();
File filee=new File(img_url);
Uri uri = Uri.fromFile(filee);
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uriimagepathcrop);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "" + "your message \n\n\n www.postemic.com");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "" + "Postemic Data");
sharingIntent.putExtra(Intent.EXTRA_TITLE, "" + "www.postemic.com");
sharingIntent.setPackage(pak);
startActivity(sharingIntent);
}
}
else
{
Builder alert = new AlertDialog.Builder(SharePost.this);
alert.setTitle("Warning");
alert.setMessage(file+" App not found");
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
}
catch(Exception e)
{
//Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}*/
}
private boolean packageInstalledOrNot(String pkgName) {
boolean app_installed = false;
try {
ApplicationInfo af = getPackageManager().getApplicationInfo(
pkgName, 0);
app_installed = true;
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
app_installed = false;
}
return app_installed;
}
public String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
}
import java.io.File;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.MediaStore.Images;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class SharePost extends Activity implements OnClickListener {
private Intent intent;
private ImageView hide_location, annonymous_post, share_post, post,video_thumb_img_v;
private LinearLayout share_post_video_thumnail_v_layout;
private EditText comments;
public static boolean isShowImageView, isShowVideoView,isShowGalleryView;
private LinearLayout fb_icon, twtricon, tumblricon, mailicon,hide_location_ly,anonymous_post_ly;
private SharePost activity = this;
private ApiServices api = new ApiServices();
private String comment = " ", key = "text";
private Bitmap img_bm;
Bitmap bitmap;
public static Bitmap video_thumb=null;
// used for move menu left and right
private RelativeLayout navigation_menu_in_rel_ly;
public static File imgFile;
public static String path;
Uri uriimagepathcrop;
Button btn;
//used for navigation
private ImageView camera_menu, profile_menu, setting_menu, search_menu,
moveBack, notification_menu, moveOver;
//private Intent intent;
private String TAG = "SharePost";
private DBController db = new DBController(activity);
String img_url,video_url,crop_url;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.sharepost);
doInitView();
doSetNavigationMenu(true, navigation_menu_in_rel_ly);
hideShowImageView();
doSettings();
}
@Override
public void onBackPressed() {
}
/***************** intilize view ********************/
private void doInitView() {
share_post = (ImageView) findViewById(R.id.share_post_img_v);
post = (ImageView) findViewById(R.id.post_comments_img_v);
comments = (EditText) findViewById(R.id.share_post_commt_edt);
share_post_video_thumnail_v_layout=(LinearLayout)findViewById(R.id.share_post_video_thumnail_v_lay);
video_thumb_img_v = (ImageView) findViewById(R.id.share_post_video_thumnail_v);
video_thumb_img_v.setOnClickListener(activity);
navigation_menu_in_rel_ly = (RelativeLayout) findViewById(R.id.sharepost_navigation_menu_relative_lay);
//me
btn=(Button) findViewById(R.id.btn);
btn.setOnClickListener(this);
//navigation_menu_in_rel_ly.setOnClickListener(this);
hide_location = (ImageView) findViewById(R.id.hide_location_img);
annonymous_post = (ImageView) findViewById(R.id.annonymous_post_img_v);
fb_icon = (LinearLayout) findViewById(R.id.facebook_icon);
twtricon = (LinearLayout) findViewById(R.id.twitter_icon);
tumblricon = (LinearLayout) findViewById(R.id.instagram_icon);
mailicon = (LinearLayout) findViewById(R.id.mail_icon);
hide_location_ly= (LinearLayout) findViewById(R.id.hide_location_lay);
anonymous_post_ly=(LinearLayout)findViewById(R.id.anonymous_post_lay);
hide_location.setOnClickListener(activity);
annonymous_post.setOnClickListener(activity);
fb_icon.setOnClickListener(activity);
twtricon.setOnClickListener(activity);
tumblricon.setOnClickListener(activity);
mailicon.setOnClickListener(activity);
post.setOnClickListener(activity);
hide_location.setOnClickListener(activity);
annonymous_post.setOnClickListener(activity);
//used for navigation
moveOver = (ImageView) findViewById(R.id.home_menu_cantrol_img_v);
camera_menu = (ImageView) findViewById(R.id.home_camera_menu_img_v);
profile_menu = (ImageView) findViewById(R.id.home_profile_menu_img_v);
setting_menu = (ImageView) findViewById(R.id.home_setting_menu_img_v);
notification_menu = (ImageView) findViewById(R.id.home_notification_menu_img_v);
search_menu = (ImageView) findViewById(R.id.home_search_menu_img_v);
moveBack = (ImageView) findViewById(R.id.home_back_menu_img_v);
moveOver.setOnClickListener(this);
camera_menu.setOnClickListener(this);
profile_menu.setOnClickListener(this);
setting_menu.setOnClickListener(this);
notification_menu.setOnClickListener(this);
search_menu.setOnClickListener(this);
moveBack.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.facebook_icon:
sharePostToSites("com.facebook.katana","Facebook");
break;
case R.id.instagram_icon:
sharePostToSites("com.instagram.android","Instagram");
break;
case R.id.twitter_icon:
sharePostToSites("com.twitter.android","Twitter");
break;
case R.id.mail_icon:
sharePostToSites("com.google.android.gm","Gmail");
break;
case R.id.hide_location_img:
doHideLocationSettings();
break;
case R.id.annonymous_post_img_v:
doAnonyomousSettings();
break;
case R.id.share_post_video_thumnail_v:
//play video from video sdcard url
try {
String url= Common.getPostCommentsVideoUrl(activity);
Common.printLog("---url is ---", "-"+url);
if(Build.VERSION.SDK_INT<19)
{
intent =new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(Common.getPostCommentsVideoUrl(activity)), "video/*");
startActivity(intent);
}
else
{
//used for kitkat and above
Uri uri=Uri.fromFile(new File(url));
intent =new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");
startActivity(intent);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
case R.id.post_comments_img_v:
if (!Common.getPostCommentsImageUrl(activity).equals("0")) {
key = "image";
} else if (!Common.getPostCommentsVideoUrl(activity).equals("0")) {
key = "video";
}else if(isShowGalleryView){
key = "image";
} else {
key = "text";
}
getInputValue();
/*if (comment.length() > 0)
{
*/
if (Common.isInternetOn(activity)) {
// new uploadvideo().execute();
if(PostemicService.latitude>4 && PostemicService.longitude>4)
{
if(Camera_.booli==true){
Log.i("In","booli if");
api.doPostComment(activity, Common.getUserId(activity),
Common.getAnonymoutPost(activity),
Common.getHideLocation(activity), key, comment,
PostemicService.latitude,PostemicService.longitude,video_thumb);
}else{
api.doPostComment(activity, Common.getUserId(activity),
Common.getAnonymoutPost(activity),
Common.getHideLocation(activity), key, comment,
PostemicService.latitude,PostemicService.longitude,bitmap);
}
/*api.doPostComment(activity, Common.getUserId(activity),
Common.getAnonymoutPost(activity),
Common.getHideLocation(activity), key, comment,
PostemicService.latitude,PostemicService.longitude,bitmap);*/
}else {
Common.showToast(activity, "Your location doesn't find !", Toast.LENGTH_SHORT);
}
} else {
Common.showToast(activity,
getString(R.string.network_unavailable),
Toast.LENGTH_SHORT);
}
/* }
else
{
Common.showToast(activity, "Comments field is required",Toast.LENGTH_SHORT);
}*/
break;
case R.id.home_menu_cantrol_img_v:
onHomeClickForMoveOver();
btn.setVisibility(View.VISIBLE);
//me
// navigation_menu_in_rel_ly.setVisibility(View.VISIBLE);
//finish();
break;
case R.id.home_camera_menu_img_v:
intent = new Intent(activity, Camera_.class);
startActivity(intent);
finish();
break;
case R.id.home_profile_menu_img_v:
if(Common.isInternetOn(activity)){
api.doGetProfilePostComments(activity, Common.getUserId(activity),"me");
}else{
Common.showToast(activity, getString(R.string.network_unavailable), Toast.LENGTH_SHORT);
}
break;
case R.id.home_setting_menu_img_v:
//used only for postemic points
if (Common.isInternetOn(activity)) {
api.doGetPostemicPoint(activity,Common.getUserId(activity),"me");
} else {
Common.showToast(activity,getString(R.string.network_unavailable),Toast.LENGTH_SHORT);
}
break;
case R.id.home_notification_menu_img_v:
// get notif_list from db and save in notif list in api services
boolean notif_is_exist = db.getAllNotification();
Common.printLog(TAG, " notif is exist " + notif_is_exist);
intent = new Intent(activity, Notification_.class);
startActivity(intent);
finish();
break;
case R.id.home_search_menu_img_v:
// call api of getappuser list
if (Common.isInternetOn(activity)) {
api.doGetAllAppUser(activity);
} else {
Common.showToast(activity,
getString(R.string.network_unavailable),
Toast.LENGTH_SHORT);
}
break;
case R.id.home_back_menu_img_v:
onBackClickMoveBack();
btn.setVisibility(View.GONE);
api.doGetComments1(activity, Common.getUserId(activity));
break;
case R.id.btn:
onBackClickMoveBack();
btn.setVisibility(View.GONE);
break;
/*//me
case R.id.home_navigation_menu_relative_lay:
onBackClickMoveBack();
break;*/
}
}
/**************** get input value from edit text **********************/
private void getInputValue() {
comment = comments.getText().toString().trim();
}
/****************** Facebook icon click click listener ******************/
private void onFacebookIconClick() {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Text...");
PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(
sharingIntent, PackageManager.MATCH_DEFAULT_ONLY);
Log.d("app", resolvedInfoList.toString());
boolean resolved = false;
for (ResolveInfo resolveInfo : resolvedInfoList) {
if (resolveInfo.activityInfo.packageName
.startsWith("com.facebook.katana")) {
sharingIntent.setClassName(
resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name);
resolved = true;
break;
}
}
if (resolved) {
startActivity(sharingIntent);
} else {
Builder alert = new AlertDialog.Builder(SharePost.this);
alert.setTitle("Warning");
alert.setMessage("Facebook App not found");
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
}
/************** on twitter icon click listener ***************/
private void onTwitterIconClick() {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Text...");
PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(
sharingIntent, PackageManager.MATCH_DEFAULT_ONLY);
boolean resolved = false;
for (final ResolveInfo app : resolvedInfoList)
{
if ("com.twitter.android.PostActivity".equals(app.activityInfo.name))
{
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
activity.applicationInfo.packageName, activity.name);
sharingIntent.addCategory(Intent.CATEGORY_LAUNCHER);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
sharingIntent.setComponent(name);
resolved = true;
break;
}
}
if (resolved) {
startActivity(sharingIntent);
} else {
Builder alert = new AlertDialog.Builder(SharePost.this);
alert.setTitle("Warning");
alert.setMessage("Twitter App not found");
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
}
/**************** on mail icon click ****************/
private void onMailIconClick() {
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "Text...");
PackageManager packManager = getPackageManager();
List<ResolveInfo> resolvedInfoList = packManager.queryIntentActivities(
sharingIntent, PackageManager.MATCH_DEFAULT_ONLY);
Log.d("app", resolvedInfoList.toString());
boolean resolved = false;
for (final ResolveInfo app : resolvedInfoList) {
Log.d("app", app.activityInfo.name);
if ((app.activityInfo.name).startsWith("com.google.android.gm")) {
final ActivityInfo activity = app.activityInfo;
final ComponentName name = new ComponentName(
activity.applicationInfo.packageName, activity.name);
sharingIntent.addCategory(Intent.CATEGORY_LAUNCHER);
sharingIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
sharingIntent.setComponent(name);
resolved = true;
break;
}
}
if (resolved) {
startActivity(sharingIntent);
} else {
Builder alert = new AlertDialog.Builder(SharePost.this);
alert.setTitle("Warning");
alert.setMessage("Gmail App not found");
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
}
/************ hide and show image view for post ***********/
private void hideShowImageView()
{
if (isShowImageView)
{
Log.d("in share post", "in share post");
share_post.setVisibility(View.VISIBLE);
share_post_video_thumnail_v_layout.setVisibility(View.GONE);
imgFile = new File(Common.getPostCommentsImageUrl(activity));
img_url="img";
video_url="";
crop_url="";
/*Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
if(bitmap != null)
{
share_post.setImageBitmap(bitmap);
}*/
//Toast.makeText(getApplicationContext(), "img path: "+imgFile.toString(), Toast.LENGTH_SHORT).show();
Intent intent = getIntent();
path = intent.getStringExtra("path");
if(imgFile.exists())
{
img_bm = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
if (img_bm != null)
{
String path = imgFile.getAbsolutePath();
Uri uri = Uri.parse(path);
share_post.setImageBitmap(img_bm);
}
}
} else {
Common.setPostCommentsImageUrl(activity, "0");
}
if (isShowVideoView) {
share_post.setVisibility(View.GONE);
share_post_video_thumnail_v_layout.setVisibility(View.VISIBLE);
imgFile = new File(Common.getPostCommentsVideoUrl(activity));
/*img_url="";
video_url="video";*/
img_url="";
video_url="vid";
crop_url="";
//Toast.makeText(getApplicationContext(), "vdo path: "+imgFile.toString(), Toast.LENGTH_SHORT).show();
if (Common.getPostCommentsVideoUrl(activity).length()>5) {
video_thumb=Common.getThumbnailFromVideo(activity, Common.getPostCommentsVideoUrl(activity));
share_post_video_thumnail_v_layout.setBackgroundDrawable(Common.getDrawableFromBitmap(activity, video_thumb));
}
} else {
Common.setPostCommentsVideoUrl(activity, "0");
}
if (isShowGalleryView) {
share_post.setVisibility(View.VISIBLE);
imgFile=new File(Common.getPostCommentGalleryImage(activity));
/*img_url="imgcrop";
video_url="vdocrop";*/
img_url="";
video_url="";
crop_url="crop";
if (!Common.getPostCommentGalleryImage(activity).equals("0")) {
if(Camera_.booli==true){
Log.i("in","share if");
//Toast.makeText(activity, "In Share If", Toast.LENGTH_SHORT).show();
share_post.setImageBitmap(Common.StringToBitMap(Common.getPostCommentGalleryImage(activity)));
Bitmap bm=Common.StringToBitMap(Common.getPostCommentGalleryImage(activity));
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
img_url= Images.Media.insertImage(getContentResolver(), bm, "title", null);
SharedPreferences sharedpreferences = getApplicationContext().getSharedPreferences("shareData", Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();
editor.putString("delete", img_url);
editor.commit();
Log.i("URLLL",""+img_url);
uriimagepathcrop=Uri.parse(img_url);
}else{
//Toast.makeText(activity, "In Share else", Toast.LENGTH_SHORT).show();
Log.i("in","share else");
Intent intent = getIntent();
bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
path = intent.getStringExtra("path");
img_url=intent.getStringExtra("path");
SharedPreferences sharedpreferences = getApplicationContext().getSharedPreferences("shareData", Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();
editor.putString("delete", path);
editor.commit();
uriimagepathcrop=Uri.parse(img_url);
Log.i("Path",""+path);
}
/*share_post.setImageBitmap(Common.StringToBitMap(Common.getPostCommentGalleryImage(activity)));
Bitmap bm=Common.StringToBitMap(Common.getPostCommentGalleryImage(activity));
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
img_url= Images.Media.insertImage(getContentResolver(), bm, "title", null);
Log.i("URLLL",""+img_url);
uriimagepathcrop=Uri.parse(img_url);
//share_post.setImageBitmap(bm);
*/
/*ByteArrayOutputStream bytes = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
String path_ = Images.Media.insertImage(getContentResolver(), bitmap, "Title", null);
//
Log.i("FI","c"+path);
*/
}
}else {
Common.setPostCommentGalleryImage(activity, "0");
}
if(!isShowVideoView && !isShowGalleryView && !isShowImageView)
{
img_url="";
video_url="";
crop_url="";
}
}
/************ hide and show image view for post ***********/
/*private void hideShowImageView()
{
if (isShowImageView)
{
Log.d("in share post", "in share post");
share_post.setVisibility(View.VISIBLE);
share_post_video_thumnail_v_layout.setVisibility(View.GONE);
File imgFile = new File(Common.getPostCommentsImageUrl(activity));
Intent intent = getIntent();
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapImage");
if(bitmap != null)
{
share_post.setImageBitmap(bitmap);
}
if(imgFile.exists())
{
img_bm = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
if (img_bm != null)
{
share_post.setImageBitmap(img_bm);
}
}
} else {
Common.setPostCommentsImageUrl(activity, "0");
}
if (isShowVideoView) {
share_post.setVisibility(View.GONE);
share_post_video_thumnail_v_layout.setVisibility(View.VISIBLE);
if (Common.getPostCommentsVideoUrl(activity).length()>5) {
video_thumb=Common.getThumbnailFromVideo(activity, Common.getPostCommentsVideoUrl(activity));
share_post_video_thumnail_v_layout.setBackgroundDrawable(Common.getDrawableFromBitmap(activity, video_thumb));
}
} else {
Common.setPostCommentsVideoUrl(activity, "0");
}
if (isShowGalleryView) {
share_post.setVisibility(View.VISIBLE);
if (!Common.getPostCommentGalleryImage(activity).equals("0")) {
share_post.setImageBitmap(Common.StringToBitMap(Common.getPostCommentGalleryImage(activity)));
}
}else {
Common.setPostCommentGalleryImage(activity, "0");
}
}
*/
/************ set setting status ***********/
private void doSettings() {
if (Common.getHideLocation(activity).equals("0")) {
hide_location.setImageResource(R.drawable.worng);
hide_location_ly.setBackgroundColor(getResources().getColor(R.color.gray));
} else {
hide_location.setImageResource(R.drawable.rightbutton);
hide_location_ly.setBackgroundColor(getResources().getColor(R.color.app_backgroud_color));
}
if (Common.getAnonymoutPost(activity).equals("0")) {
annonymous_post.setImageResource(R.drawable.worng);
anonymous_post_ly.setBackgroundColor(getResources().getColor(R.color.gray));
} else {
annonymous_post.setImageResource(R.drawable.rightbutton);
anonymous_post_ly.setBackgroundColor(getResources().getColor(R.color.app_backgroud_color));
}
}
/************ manage hide locaion setting ***********/
private void doHideLocationSettings() {
if (Common.getHideLocation(activity).equals("0")) {
hide_location.setImageResource(R.drawable.rightbutton);
Common.setHideLocation(activity, "1");
hide_location_ly.setBackgroundColor(getResources().getColor(R.color.app_backgroud_color));
} else {
hide_location.setImageResource(R.drawable.worng);
Common.setHideLocation(activity, "0");
hide_location_ly.setBackgroundColor(getResources().getColor(R.color.gray));
}
}
/************ manage anonyomous setting ***********/
private void doAnonyomousSettings() {
if (Common.getAnonymoutPost(activity).equals("0")) {
annonymous_post.setImageResource(R.drawable.rightbutton);
Common.setAnonymoutPost(activity, "1");
anonymous_post_ly.setBackgroundColor(getResources().getColor(R.color.app_backgroud_color));
} else {
annonymous_post.setImageResource(R.drawable.worng);
Common.setAnonymoutPost(activity, "0");
anonymous_post_ly.setBackgroundColor(getResources().getColor(R.color.gray));
}
}
/****** set navigation menu in left and right *******/
private void doSetNavigationMenu(boolean in_left, RelativeLayout nav_lay) {
if (in_left) {
nav_lay.setGravity(Gravity.LEFT);
} else {
nav_lay.setGravity(Gravity.RIGHT);
}
}
/************ on postemic home click for move over *************/
private void onHomeClickForMoveOver() {
// comment bcos menu show only left side
// if (Common.getPostemicMenu(activity).equals("0")) {
if (Common.getDeviceDensityName(activity).equals("ldpi")) {
Common.doAmimatonFromLeft(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getLeft(), moveBack);
} else if (Common.getDeviceDensityName(activity).equals("mdpi")) {
Common.doAmimatonFromLeft(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getLeft(), moveBack);
} else if (Common.getDeviceDensityName(activity).equals("hdpi")) {
Common.doAmimatonFromLeft(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getLeft(), moveBack);
}
//me
else if (Common.getDeviceDensityName(activity).equals("xxhdpi")) {
Common.doAmimatonFromLeftXXhdpi(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getLeft(), moveBack);
}
else if (Common.getDeviceDensityName(activity).equals("xxxhdpi")) {
Common.doAmimatonFromLeftXXXhdpi(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getLeft(), moveBack);
}
//
else {
Common.doAmimatonFromLeftForXhdpi(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
}
/*
} else if (Common.getPostemicMenu(activity).equals("1")) {
if (Common.getDeviceDensityName(activity).equals("ldpi")) {
Common.doAmimatonFromRight(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getRight(), moveBack);
} else if (Common.getDeviceDensityName(activity).equals("mdpi")) {
Common.doAmimatonFromRight(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getRight(), moveBack);
} else if (Common.getDeviceDensityName(activity).equals("hdpi")) {
Common.doAmimatonFromRight(moveOver, camera_menu, profile_menu,
setting_menu, notification_menu, search_menu,
moveOver.getBottom(), moveOver.getRight(), moveBack);
} else {
Common.doAmimatonFromRightForXhdpi(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getRight(),
moveBack);
}
}
*/
}
/************ on postemic back click for back from over *************/
private void onBackClickMoveBack() {
// if (Common.getPostemicMenu(activity).equals("0")) {
if (Common.getDeviceDensityName(activity).equals("ldpi")) {
Common.doResetAmimatonFromLeft(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
} else if (Common.getDeviceDensityName(activity).equals("mdpi")) {
Common.doResetAmimatonFromLeft(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
} else if (Common.getDeviceDensityName(activity).equals("hdpi")) {
Common.doResetAmimatonFromLeft(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
}
//me
else if (Common.getDeviceDensityName(activity).equals("xxhdpi")) {
Common.doResetAmimatonFromLeftXXhdpi(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
}
else if (Common.getDeviceDensityName(activity).equals("xxxhdpi")) {
Common.doResetAmimatonFromLeftXXXhdpi(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
}
//
else {
Common.doResetAmimatonFromLeftForXhdpi(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getLeft(),
moveBack);
}
/*
} else if (Common.getPostemicMenu(activity).equals("1")) {
if (Common.getDeviceDensityName(activity).equals("ldpi")) {
Common.doResetAmimatonFromRight(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getRight(),
moveBack);
} else if (Common.getDeviceDensityName(activity).equals("mdpi")) {
Common.doResetAmimatonFromRight(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getRight(),
moveBack);
} else if (Common.getDeviceDensityName(activity).equals("hdpi")) {
Common.doResetAmimatonFromRight(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getRight(),
moveBack);
} else {
Common.doResetAmimatonFromRightForXhdpi(moveOver, camera_menu,
profile_menu, setting_menu, notification_menu,
search_menu, moveOver.getBottom(), moveOver.getRight(),
moveBack);
}
}
*/
}
// by pradeep
private void sharePostToSites(String pak, String file) {
// TODO Auto-generated method stub
try{
if(packageInstalledOrNot(pak))
{
getInputValue();
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
if (img_url.length()!=0 || crop_url.length()!=0)
{
Uri uri = Uri.fromFile(imgFile);
Log.d("UriPath: ", "" + uri);
sharingIntent.setType("image/*");
if(img_url.length()>0)
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
else
sharingIntent.putExtra(Intent.EXTRA_STREAM, uriimagepathcrop);
sharingIntent.putExtra(Intent.EXTRA_TEXT, comment);
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sharingIntent.setPackage(pak);
startActivity(sharingIntent);
}
else if (video_url.length()!=0)
{
if(!file.equalsIgnoreCase("Twitter"))
{
Uri uri = Uri.fromFile(imgFile);
Log.d("UriPath: ", "" + uri);
sharingIntent.setType("video/*");
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.putExtra(Intent.EXTRA_TEXT, comment);
sharingIntent.setPackage(pak);
startActivity(sharingIntent);
}
else
{
Toast toast=Toast.makeText(getApplicationContext(), "Video not uplaoded to Twitter", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
else
{
/*sharingIntent.setType("text/plain");
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sharingIntent.putExtra(Intent.EXTRA_TEXT, comment);
sharingIntent.setPackage(pak);
startActivity(sharingIntent);*/
if(!(file.equalsIgnoreCase("facebook") || file.equalsIgnoreCase("Instagram")))
{
sharingIntent.setType("text/plain");
sharingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sharingIntent.putExtra(Intent.EXTRA_TEXT, comment);
sharingIntent.setPackage(pak);
startActivity(sharingIntent);
}
else
{
Toast.makeText(getApplicationContext(), "Text not uploaded to "+file, Toast.LENGTH_SHORT).show();
}
}
}
else
{
Toast.makeText(activity, file+" not found in your device", Toast.LENGTH_SHORT).show();
}
}
catch(Exception e)
{
e.printStackTrace();
}
/* try{
if(packageInstalledOrNot(pak))
{
Intent sharingIntent = new Intent(Intent.ACTION_SEND);
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Postemic");
if (img_url.length()>0 && img_url.length()<4)
{
Uri uri = Uri.fromFile(imgFile);
Log.d("UriPath: ", "" + uri);
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "" + "your message \n\n\n www.postemic.com");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "" + "Postemic Data");
sharingIntent.putExtra(Intent.EXTRA_TITLE, "" + "www.postemic.com");
sharingIntent.setPackage(pak);
startActivity(sharingIntent);
}
else if (video_url.length()>0 && video_url.length()<4)
{
if(!file.equalsIgnoreCase("Twitter"))
{
Uri uri = Uri.fromFile(imgFile);
Log.d("UriPath: ", "" + uri);
sharingIntent.setType("video/*");
sharingIntent.putExtra(Intent.EXTRA_TEXT, "" + "your message \n\n\n www.postemic.com");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "" + "Postemic Data");
sharingIntent.putExtra(Intent.EXTRA_TITLE, "" + "www.postemic.com");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uri);
sharingIntent.setPackage(pak);
startActivity(sharingIntent);
}
else
{
Toast toast=Toast.makeText(getApplicationContext(), "Video not uplaoded to Twitter", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
else
{
//Toast.makeText(getApplicationContext(), img_url, Toast.LENGTH_LONG).show();
File filee=new File(img_url);
Uri uri = Uri.fromFile(filee);
sharingIntent.setType("image/*");
sharingIntent.putExtra(Intent.EXTRA_STREAM, uriimagepathcrop);
sharingIntent.putExtra(Intent.EXTRA_TEXT, "" + "your message \n\n\n www.postemic.com");
sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "" + "Postemic Data");
sharingIntent.putExtra(Intent.EXTRA_TITLE, "" + "www.postemic.com");
sharingIntent.setPackage(pak);
startActivity(sharingIntent);
}
}
else
{
Builder alert = new AlertDialog.Builder(SharePost.this);
alert.setTitle("Warning");
alert.setMessage(file+" App not found");
alert.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alert.show();
}
}
catch(Exception e)
{
//Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}*/
}
private boolean packageInstalledOrNot(String pkgName) {
boolean app_installed = false;
try {
ApplicationInfo af = getPackageManager().getApplicationInfo(
pkgName, 0);
app_installed = true;
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
app_installed = false;
}
return app_installed;
}
public String getRealPathFromURI(Uri contentUri) {
String[] proj = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
}
No comments:
Post a Comment