instantiateItem is calling 3 times and button is not clickable - android

instantiateItem is calling 3 times and buttons are not clickable
#Override
public Object instantiateItem(ViewGroup container, int position) {
// TODO Auto-generated method stub
inflater1 = (LayoutInflater) context1.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View itemView = inflater1.inflate(R.layout.pagerlayout, container,
false);
Log.v("", "CHecking foregroung3");
((ScrollView)itemView. findViewById(R.id.scrollview)).scrollTo(0, 0);
articleTitle_textview = (TextView)itemView.findViewById(R.id.articletitle);
postingTime_textview = (TextView)itemView.findViewById(R.id.postingtime);
articleContent_webview = (WebView)itemView.findViewById(R.id.webview);
csSliderShow=(RelativeLayout)itemView.findViewById(R.id.slide);
countTxt = (TextView)itemView.findViewById(R.id.Count_textView);
previousTxt = (TextView)itemView.findViewById(R.id.prev_textview);
nextText = (TextView)itemView.findViewById(R.id.next_textview);
tab_layout_parent = (RelativeLayout)itemView.findViewById(R.id.tab_layout_parent);
tab_layout = (LinearLayout)itemView.findViewById(R.id.tab_layout);
relatedTxt=(TextView)itemView.findViewById(R.id.related);
relatedArticlesLinearLayoutGridView = (LinearLayout)itemView.findViewById(R.id.linear_related_articles_gridview);
gridView = new ExpandableHeightGridView(ArticleViewActivity.this);
articleContent_webview.invalidate();
//WebView wv = (WebView) findViewById(R.id.webview);
articleContent_webview.getSettings().setBuiltInZoomControls(false);
articleContent_webview.getSettings().setJavaScriptEnabled(true);
try{
/*if (indexofArticle >= 0)
{
if(relatedArticlesLinearLayoutGridView.getChildAt(0) != null)
{
int movement = relatedArticlesLinearLayoutGridView.getChildAt(0).getWidth()* indexofArticle;
//mHoriArticleViewList.scrollTo(movement, 0);
}
}*/
articleTitle_textview.setText(fetchmodel.mTitle);
postingTime_textview.setText(fetchmodel.mPubDate);
String s="<head><style><meta name='viewport' content='target-densityDpi=device-dpi' body{font-size:17px;}/></style></head>";
String addwidth = fetchmodel.mHtmlText;
//Log.v("","Checking Text Before:"+fetchmodel.mHtmlText);
String addwidth1 =addwidth.replace("w=320&q=", "w="+width+"&q=");
articleContent_webview.setWebViewClient(new WebViewClient(){
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
Log.v("URL : ", url);
if(url.contains("http:"))
{
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
return true;
}
return false;
}
#Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
#Override
public void onPageStarted(WebView view, String url,
Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
});
articleContent_webview.getSettings().setJavaScriptEnabled(true);
articleContent_webview.loadDataWithBaseURL("", s+addwidth1, "text/html", "utf8", "");
//Log.v("","Checking Text After:"+addwidth1);
if(fetchmodel.PhotoFeatureList.size() > 0)
{
csSliderShow.setVisibility(View.VISIBLE);
articleTitle_textview.setVisibility(View.VISIBLE);
postingTime_textview.setVisibility(View.VISIBLE);
csSliderShow.invalidate();
int valuimg=imagNum+1;
countTxt.setText("Slide "+valuimg+" of "+fetchmodel.PhotoFeatureList.size());
String image_url = fetchmodel.PhotoFeatureList.get(imagNum).imgUrl;
String image_url1 = image_url.replace("w=100", "w=300");
csImageLoader.DisplayImage(image_url1, R.drawable.loading, csImageSlider, 0);
titleTxt.setText(fetchmodel.PhotoFeatureList.get(imagNum).subTitle);
headlineTxt.setText(fetchmodel.PhotoFeatureList.get(imagNum).headline);
}
else
{
csSliderShow.setVisibility(View.GONE);
articleTitle_textview.setVisibility(View.GONE);
postingTime_textview.setVisibility(View.GONE);
}
try{
if (fetchmodel.sectionContainerList.size()>0 ) {
Log.v("","CHECKING TABS:");
tab_layout_parent.setVisibility(View.VISIBLE);
tab1 = (Button)itemView.findViewById(R.id.tab1);
tab2 = (Button)itemView.findViewById(R.id.tab2);
tab3 = (Button)itemView.findViewById(R.id.tab3);
imgPoster = (ImageView)itemView.findViewById(R.id.imgPoster0);
TextView profile =(TextView)itemView.findViewById(R.id.profile0);
TextView photos =(TextView)itemView.findViewById(R.id.photos0);
TextView videos =(TextView)itemView.findViewById(R.id.videos0);
countTab = 100;
imgLoader.DisplayImage(fetchmodel.sectionContainerList.get(0).minSectionImgURL, R.drawable.loading, imgPoster, 7);
if (fetchmodel.sectionContainerList.size() == 1) {
tab2.setVisibility(View.GONE);
tab3.setVisibility(View.GONE);
tab1.setText(fetchmodel.sectionContainerList.get(0).minSectionTitle);
imgPoster.setVisibility(View.VISIBLE);
profile.setVisibility(View.VISIBLE);
photos.setVisibility(View.VISIBLE);
videos.setVisibility(View.VISIBLE);
}else if (fetchmodel.sectionContainerList.size() == 2) {
tab3.setVisibility(View.GONE);
tab1.setText(fetchmodel.sectionContainerList.get(0).minSectionTitle);
tab2.setText(fetchmodel.sectionContainerList.get(1).minSectionTitle);
imgPoster.setVisibility(View.VISIBLE);
profile.setVisibility(View.VISIBLE);
photos.setVisibility(View.VISIBLE);
videos.setVisibility(View.VISIBLE);
}else if(fetchmodel.sectionContainerList.size() >= 3){
Log.v("","CHECKING TABS:3");
tab1.setText(fetchmodel.sectionContainerList.get(0).minSectionTitle);
tab2.setText(fetchmodel.sectionContainerList.get(1).minSectionTitle);
tab3.setText(fetchmodel.sectionContainerList.get(2).minSectionTitle);
imgPoster.setVisibility(View.VISIBLE);
profile.setVisibility(View.VISIBLE);
photos.setVisibility(View.VISIBLE);
videos.setVisibility(View.VISIBLE);
imgLoader.DisplayImage(fetchmodel.sectionContainerList.get(0).minSectionImgURL, R.drawable.loading, imgPoster, 7);
}
tab1.setTextColor(Color.RED);
tab2.setTextColor(Color.BLACK);
tab3.setTextColor(Color.BLACK);
tab2.setBackgroundColor(getResources().getColor(R.color.darkgreen));
tab3.setBackgroundColor(Color.GRAY);
tab1.setFocusable(false);
tab2.setFocusable(false);
tab3.setFocusable(false);
tab1.setBackgroundDrawable(null);
tab2.setBackgroundResource(R.drawable.back_button);
tab3.setBackgroundResource(R.drawable.back_button);
tab1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
tab1.setTextColor(Color.RED);
tab2.setTextColor(Color.BLACK);
tab3.setTextColor(Color.BLACK);
tab2.setBackgroundColor(getResources().getColor(R.color.darkgreen));
tab3.setBackgroundColor(Color.GRAY);
tab1.setBackgroundDrawable(null);
tab2.setBackgroundResource(R.drawable.back_button);
tab3.setBackgroundResource(R.drawable.back_button);
countTab = 100;
imgLoader.DisplayImage(fetchmodel.sectionContainerList.get(0).minSectionImgURL, R.drawable.loading, imgPoster, 7);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
tab2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
tab1.setTextColor(Color.BLACK);
tab2.setTextColor(Color.RED);
tab3.setTextColor(Color.BLACK);
tab1.setBackgroundColor(Color.GRAY);
tab3.setBackgroundColor(Color.GRAY);
tab2.setBackgroundDrawable(null);
tab1.setBackgroundResource(R.drawable.back_button);
tab3.setBackgroundResource(R.drawable.back_button);
countTab = 200;
imgLoader.DisplayImage(fetchmodel.sectionContainerList.get(1).minSectionImgURL, R.drawable.loading, imgPoster, 7);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
tab3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try {
tab1.setTextColor(Color.BLACK);
tab2.setTextColor(Color.BLACK);
tab3.setTextColor(Color.RED);
tab1.setBackgroundColor(Color.GRAY);
tab2.setBackgroundColor(Color.GRAY);
tab3.setBackgroundDrawable(null);
tab2.setBackgroundResource(R.drawable.back_button);
tab1.setBackgroundResource(R.drawable.back_button);
countTab = 300;
imgLoader.DisplayImage(fetchmodel.sectionContainerList.get(2).minSectionImgURL, R.drawable.loading, imgPoster, 7);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
imgPoster.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
if(countTab == 100){
if(fetchmodel.sectionContainerList.get(0).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, ActorProfileActivity.class);
intent.putExtra("personID", fetchmodel.sectionContainerList.get(0).minEntryId);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(0).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, MovieProfileActivity.class);
intent.putExtra("movieID", fetchmodel.sectionContainerList.get(0).minEntryId);
startActivity(intent);
}
}else if (countTab == 200) {
if(fetchmodel.sectionContainerList.get(1).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, ActorProfileActivity.class);
intent.putExtra("personID", fetchmodel.sectionContainerList.get(1).minEntryId);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(1).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, MovieProfileActivity.class);
intent.putExtra("movieID", fetchmodel.sectionContainerList.get(1).minEntryId);
startActivity(intent);
}
}else if (countTab == 300) {
if(fetchmodel.sectionContainerList.get(2).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, ActorProfileActivity.class);
intent.putExtra("personID", fetchmodel.sectionContainerList.get(2).minEntryId);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(2).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, MovieProfileActivity.class);
intent.putExtra("movieID", fetchmodel.sectionContainerList.get(2).minEntryId);
startActivity(intent);
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
});
profile.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
if(countTab == 100){
if(fetchmodel.sectionContainerList.get(0).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, ActorProfileActivity.class);
intent.putExtra("personID", fetchmodel.sectionContainerList.get(0).minEntryId);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(0).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, MovieProfileActivity.class);
intent.putExtra("movieID", fetchmodel.sectionContainerList.get(0).minEntryId);
startActivity(intent);
}
}else if (countTab == 200) {
if(fetchmodel.sectionContainerList.get(1).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, ActorProfileActivity.class);
intent.putExtra("personID", fetchmodel.sectionContainerList.get(1).minEntryId);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(1).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, MovieProfileActivity.class);
intent.putExtra("movieID", fetchmodel.sectionContainerList.get(1).minEntryId);
startActivity(intent);
}
}
else if (countTab == 300) {
if(fetchmodel.sectionContainerList.get(2).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, ActorProfileActivity.class);
intent.putExtra("personID", fetchmodel.sectionContainerList.get(2).minEntryId);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(2).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, MovieProfileActivity.class);
intent.putExtra("movieID", fetchmodel.sectionContainerList.get(2).minEntryId);
startActivity(intent);
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
});
photos.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
if(countTab == 100){
if(fetchmodel.sectionContainerList.get(0).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, PhotosLandingActitivity.class);
intent.putExtra("photosID", fetchmodel.sectionContainerList.get(0).minEntryId);
intent.putExtra("type", fetchmodel.sectionContainerList.get(0).minType);
intent.putExtra("actions", "FetchPhotos");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(0).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, PhotosLandingActitivity.class);
intent.putExtra("photosID", fetchmodel.sectionContainerList.get(0).minEntryId);
intent.putExtra("type", fetchmodel.sectionContainerList.get(0).minType);
intent.putExtra("actions", "FetchPhotos");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}else if (countTab == 200) {
if(fetchmodel.sectionContainerList.get(1).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, PhotosLandingActitivity.class);
intent.putExtra("photosID", fetchmodel.sectionContainerList.get(1).minEntryId);
intent.putExtra("type", fetchmodel.sectionContainerList.get(1).minType);
intent.putExtra("actions", "FetchPhotos");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(1).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, PhotosLandingActitivity.class);
intent.putExtra("photosID", fetchmodel.sectionContainerList.get(1).minEntryId);
intent.putExtra("type", fetchmodel.sectionContainerList.get(1).minType);
intent.putExtra("actions", "FetchPhotos");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
else if (countTab == 300) {
if(fetchmodel.sectionContainerList.get(2).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, PhotosLandingActitivity.class);
intent.putExtra("photosID", fetchmodel.sectionContainerList.get(2).minEntryId);
intent.putExtra("type", fetchmodel.sectionContainerList.get(2).minType);
intent.putExtra("actions", "FetchPhotos");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(2).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, PhotosLandingActitivity.class);
intent.putExtra("photosID", fetchmodel.sectionContainerList.get(2).minEntryId);
intent.putExtra("type", fetchmodel.sectionContainerList.get(2).minType);
intent.putExtra("actions", "FetchPhotos");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
});
videos.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
try{
if(countTab == 100){
if(fetchmodel.sectionContainerList.get(0).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, LatestPhotosActivity.class);
intent.putExtra("videoID", fetchmodel.sectionContainerList.get(0).minEntryId);
intent.putExtra("whichscreen", 200);
intent.putExtra("type", "actor");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(0).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, LatestPhotosActivity.class);
intent.putExtra("videoID", fetchmodel.sectionContainerList.get(0).minEntryId);
intent.putExtra("whichscreen", 200);
intent.putExtra("type", "movie");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}else if (countTab == 200) {
if(fetchmodel.sectionContainerList.get(1).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, LatestPhotosActivity.class);
intent.putExtra("videoID", fetchmodel.sectionContainerList.get(1).minEntryId);
intent.putExtra("whichscreen", 200);
intent.putExtra("type", "actor");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(1).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, LatestPhotosActivity.class);
intent.putExtra("videoID", fetchmodel.sectionContainerList.get(1).minEntryId);
intent.putExtra("whichscreen", 200);
intent.putExtra("type", "movie");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}else if (countTab == 300) {
if(fetchmodel.sectionContainerList.get(2).minType.contains("actor")){
Intent intent = new Intent(ArticleViewActivity.this, LatestPhotosActivity.class);
intent.putExtra("videoID", fetchmodel.sectionContainerList.get(2).minEntryId);
intent.putExtra("whichscreen", 200);
intent.putExtra("type", "actor");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}else if(fetchmodel.sectionContainerList.get(2).minType.contains("movie"))
{
Intent intent = new Intent(ArticleViewActivity.this, LatestPhotosActivity.class);
intent.putExtra("videoID", fetchmodel.sectionContainerList.get(2).minEntryId);
intent.putExtra("whichscreen", 200);
intent.putExtra("type", "movie");
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
}
}
}catch(Exception e)
{
e.printStackTrace();
}
}
});
}
}catch(Exception e)
{
e.printStackTrace();
}
if(relatedArticlesLinearLayoutGridView != null && relatedArticlesLinearLayoutGridView.getChildCount() > 0)
{
relatedArticlesLinearLayoutGridView.removeAllViews();
relatedArticlesLinearLayoutGridView = (LinearLayout)findViewById(R.id.linear_related_articles_gridview);
}
gridView.setNumColumns(2);
gridView.setAdapter(new LazyAdapterForRelatedArticles(mContext,fetchmodel.reLatedArticlesList));
gridView.setExpanded(true);
if(fetchmodel.reLatedArticlesList.size() > 0)
{
Log.v("","checking related:");
relatedTxt.setVisibility(View.VISIBLE);
relatedArticlesLinearLayoutGridView.setVisibility(View.VISIBLE);
}
else
{
relatedTxt.setVisibility(View.GONE);
relatedArticlesLinearLayoutGridView.setVisibility(View.GONE);
}
relatedArticlesLinearLayoutGridView.addView(gridView);
previousTxt.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
try {
imagNum--;
if(imagNum < 0)
{
imagNum=fetchmodel.PhotoFeatureList.size()-1;
}
int valuimg=imagNum+1;
countTxt.setText("Slide "+valuimg+" of "+fetchmodel.PhotoFeatureList.size());
String image_url = fetchmodel.PhotoFeatureList.get(imagNum).imgUrl;
String image_url1 = image_url.replace("w=100", "w=300");
csImageLoader.DisplayImage(image_url1, R.drawable.loading, csImageSlider, 0);
titleTxt.setText(fetchmodel.PhotoFeatureList.get(imagNum).subTitle);
headlineTxt.setText(fetchmodel.PhotoFeatureList.get(imagNum).headline);
getTracker().trackPageView("ArticleViewPage- Image:"+fetchmodel.PhotoFeatureList.get(imagNum).imgUrl);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
nextText.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{try {
imagNum++;
if(imagNum > fetchmodel.PhotoFeatureList.size()-1)
{
imagNum=0;
}
int valuimg=imagNum+1;
countTxt.setText("Slide "+valuimg+" of "+fetchmodel.PhotoFeatureList.size());
String image_url = fetchmodel.PhotoFeatureList.get(imagNum).imgUrl;
String image_url1 = image_url.replace("w=100", "w=300");
csImageLoader.DisplayImage(image_url1, R.drawable.loading, csImageSlider, 0);
titleTxt.setText(fetchmodel.PhotoFeatureList.get(imagNum).subTitle);
headlineTxt.setText(fetchmodel.PhotoFeatureList.get(imagNum).headline);
getTracker().trackPageView("ArticleViewPage- Image:"+fetchmodel.PhotoFeatureList.get(imagNum).imgUrl);
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
});
gridView.setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
pageLoadNum = 5050;
strEntryId=csFetchArticle.reLatedArticlesList.get(position).minEntryID;
imagNum=0;
if(csFetchArticle.PhotoFeatureList != null && csFetchArticle.PhotoFeatureList.size() > 0)
{
csFetchArticle.PhotoFeatureList.clear();
}
if(csFetchArticle.reLatedArticlesList != null && csFetchArticle.reLatedArticlesList.size() > 0)
{
csFetchArticle.reLatedArticlesList.clear();
}
articleContent_webview = (WebView)findViewById(R.id.webview);
sendEmptyMessageSync(SHOW_PROGRESS_DIALOG);
sendEmptyMessageAsync(FETCH_ARTICLE);
}
});
}catch(Exception e){
e.printStackTrace();
}
((ViewPager) container).addView(itemView);
//csViePageAdapter.notifyDataSetChanged();
return itemView;
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
// Remove viewpager_item.xml from ViewPager
((ViewPager) container).removeView((RelativeLayout) object);
}
}

Related

JavaBinder FAILED BINDER TRANSACTION

I am getting this error in logcat when i try to upload image grom gallery. when i upload image from camera directly it works fine. Below is my code
public class OfflineMerchantRegisterActivity extends AppCompatActivity {
EditText edtUsername, edtPassword, edtConfirmPassword, edtEmail, edtMobile, edtServiceType, edtName, edtAddress, edtCity;
Button btnRegister, btnSelectImage, btnSelectCity, btnSelectType;
ImageView imgMerchant;
String offline_service_type;
LinearLayout layoutCity, layoutServiceType;
EditText edtService;
String service;
String username, password, confirmPassword, email, mobile, serviceType, name, address, city;
Context context;
private String userChoosenTask;
private static final int CAMERA_REQUEST = 1888;
private static final int GALLERY_REQUEST = 2;
Bitmap imageBitmap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_offline_merchant_register);
context=OfflineMerchantRegisterActivity.this;
edtUsername = (EditText) findViewById(R.id.edtUsername);
edtPassword = (EditText) findViewById(R.id.edtPassword);
edtConfirmPassword = (EditText) findViewById(R.id.edtConfirmPassword);
edtEmail = (EditText) findViewById(R.id.edtEmail);
edtMobile = (EditText) findViewById(R.id.edtMobile);
edtServiceType = (EditText) findViewById(R.id.edtServiceType);
edtName = (EditText) findViewById(R.id.edtName);
edtAddress = (EditText) findViewById(R.id.edtAddress);
edtCity = (EditText) findViewById(R.id.edtCity);
edtService = (EditText) findViewById(R.id.edtService);
edtService.setText("Offline Merchant");
btnRegister = (Button) findViewById(R.id.btnRegister);
btnSelectImage = (Button) findViewById(R.id.btnSelectImage);
btnSelectCity = (Button) findViewById(R.id.btnSelectCity);
btnSelectType = (Button) findViewById(R.id.btnSelectType);
imgMerchant = (ImageView) findViewById(R.id.imgMerchant);
layoutCity = (LinearLayout) findViewById(R.id.layoutCity);
layoutServiceType = (LinearLayout) findViewById(R.id.layoutServiceType);
btnSelectCity.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(OfflineMerchantRegisterActivity.this, MerchantCityActivity.class);
startActivityForResult(intent, 3);
}
});
btnSelectType.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(OfflineMerchantRegisterActivity.this, OfflineServiceTypeListActivity.class);
startActivityForResult(intent, 1);
}
});
layoutServiceType.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
layoutCity.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
btnRegister.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (isValid()){
//registerOfflineMerchant();
Intent intent = new Intent(OfflineMerchantRegisterActivity.this, OfflineMerchantConfirmActivity.class);
intent.putExtra("username", edtUsername.getText().toString());
intent.putExtra("password", edtPassword.getText().toString());
intent.putExtra("email", edtEmail.getText().toString());
intent.putExtra("mobile", edtMobile.getText().toString());
intent.putExtra("serviceType", edtServiceType.getText().toString());
intent.putExtra("name", edtName.getText().toString());
intent.putExtra("address", edtAddress.getText().toString());
intent.putExtra("city", edtCity.getText().toString());
if (imageBitmap!=null){
intent.putExtra("imageString", getStringImage(imageBitmap));
intent.putExtra("fileName", username+".png");
}
else {
//do nothing
}
intent.putExtra("service", edtService.getText().toString());
startActivity(intent);
}
}
});
btnSelectImage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
/* Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 2);*/
selectImage();
}
});
}
public boolean isValidMail(String email) {
// TODO Auto-generated method stub
boolean isValid = false;
String expression = "^[\\w\\.-]+#([\\w\\-]+\\.)+[A-Z]{2,4}$";
CharSequence inputStr = email;
Pattern pattern = Pattern.compile(expression, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(inputStr);
if (matcher.matches()) {
isValid = true;
}
return isValid;
}
public boolean isValid(){
username = edtUsername.getText().toString().trim();
name = edtName.getText().toString().trim();
password = edtPassword.getText().toString().trim();
confirmPassword = edtConfirmPassword.getText().toString().trim();
email = edtEmail.getText().toString().trim();
mobile = edtMobile.getText().toString().trim();
serviceType = edtServiceType.getText().toString().trim();
address = edtAddress.getText().toString().trim();
city = edtCity.getText().toString().trim();
service = edtService.getText().toString().trim();
if (username.length() <=0){
Toast.makeText(OfflineMerchantRegisterActivity.this, "Please Enter Username", Toast.LENGTH_SHORT).show();
return false;
}
if (name.length() <=0){
Toast.makeText(OfflineMerchantRegisterActivity.this, "Please Enter Name", Toast.LENGTH_SHORT).show();
return false;
}
if (password.length() <=0){
Toast.makeText(OfflineMerchantRegisterActivity.this, "Please Enter Password", Toast.LENGTH_SHORT).show();
return false;
}
if (confirmPassword.length() <=0){
Toast.makeText(OfflineMerchantRegisterActivity.this, "Please Enter Password Again", Toast.LENGTH_SHORT).show();
return false;
}
if (!(password.equals(confirmPassword))) {
Toast.makeText(this, "Passwords Mismatch", Toast.LENGTH_SHORT).show();
return false;
}
if (email.length() <=0){
Toast.makeText(OfflineMerchantRegisterActivity.this, "Please Enter Email", Toast.LENGTH_SHORT).show();
return false;
}
if (!isValidMail(email)) {
Toast toast = Toast.makeText(this, "Please Enter Valid Email", Toast.LENGTH_SHORT);
toast.show();
return false;
}
if (mobile.length() <=9){
Toast.makeText(OfflineMerchantRegisterActivity.this, "Please Enter Mobile Number", Toast.LENGTH_SHORT).show();
return false;
}
if (serviceType.length() <=0){
Toast.makeText(OfflineMerchantRegisterActivity.this, "Please Select Service Type", Toast.LENGTH_SHORT).show();
return false;
}
if (address.length() <=0){
Toast.makeText(OfflineMerchantRegisterActivity.this, "Please Enter Address", Toast.LENGTH_SHORT).show();
return false;
}
if (city.length() <=0){
Toast.makeText(OfflineMerchantRegisterActivity.this, "Please Select City", Toast.LENGTH_SHORT).show();
return false;
}
if (service.length() <= 0){
Toast.makeText(OfflineMerchantRegisterActivity.this, "Please Enter As Offline Service", Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
if (requestCode == 1) {
offline_service_type = data.getStringExtra("offlineServiceType");
edtServiceType.setText(offline_service_type);
}
if (resultCode == Activity.RESULT_OK){
if (requestCode == 3){
city = data.getStringExtra("city");
edtCity.setText(city);
}
}
if (resultCode == RESULT_OK && null != data) {
if (requestCode == GALLERY_REQUEST) {
Uri URI = data.getData();
String[] FILE = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(URI, FILE, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(FILE[0]);
String imageDecode = cursor.getString(columnIndex);
cursor.close();
imageBitmap = BitmapFactory.decodeFile(imageDecode);
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
imgMerchant.setImageBitmap(imageBitmap);
//uploadImageToServer(getStringImage(bmp), username);
} else if (requestCode == CAMERA_REQUEST) {
imageBitmap = (Bitmap) data.getExtras().get("data");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
File destination = new File(Environment.getExternalStorageDirectory(),
System.currentTimeMillis() + ".jpg");
FileOutputStream fo;
try {
destination.createNewFile();
fo = new FileOutputStream(destination);
fo.write(bytes.toByteArray());
fo.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
imgMerchant.setImageBitmap(imageBitmap);
//uploadImageToServer(getStringImage(thumbnail), username);
}
}
}
}
public String getStringImage(Bitmap bmp) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.JPEG, 90, outputStream);
byte[] imageBytes = outputStream.toByteArray();
String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
return encodedImage;
}
#Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
switch (requestCode) {
case Utility.MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE:
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (userChoosenTask.equals("Take Photo"))
cameraIntent();
else if (userChoosenTask.equals("Choose from Library"))
galleryIntent();
} else {
//code for deny
}
break;
}
}
private void selectImage() {
final CharSequence[] items = {"Take Photo", "Choose from Library",
"Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Add Photo");
builder.setItems(items, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int item) {
boolean result = Utility.checkPermission(context);
if (items[item].equals("Take Photo")) {
userChoosenTask = "Take Photo";
if (result)
cameraIntent();
} else if (items[item].equals("Choose from Library")) {
userChoosenTask = "Choose from Library";
if (result)
galleryIntent();
} else if (items[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
}
private void galleryIntent() {
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, GALLERY_REQUEST);
//startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE);
}
private void cameraIntent() {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_REQUEST);
}
public void onBackPressed() {
OfflineMerchantRegisterActivity.this.finish();
super.onBackPressed();
}
}
How to solve this error ? after selecting image from gallery, app crash error.
This error mostly occurs when the data you are filling in the intent is more than the system is able to transfer through Intent bundle. Check to see the size of all the things you are putting in the bundle. And also check to see that the image you are selecting from gallery is not very large, as the system may not be able to transfer the image from gallery to you app. The camera code is working because the camera app transfers a low-resolution image through the Intent.

how to add multiple imageview dynamically

im about to make like photo album so we can upload multiple photo (like facebook, etc)
ivAttachment1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(strPhoto1 == "" && PageType.equals("NewRequestMedical")) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
photoTemp = "photo1";
}
else if(strPhoto1 == "" && !PageType.equals("NewRequestMedical"))
{
Toast.makeText(getApplicationContext(), "there is no attachment on this request",
Toast.LENGTH_SHORT).show();
}else {
Intent i = new Intent(MedicalClaim.this, DetailPhotoMedical.class);
/* i.putExtra("photo", strPhoto1);*/
Bundle extras = new Bundle();
extras.putString("photo", strPhoto1);
extras.putString("photoNo","photo1");
extras.putString("PageTypeRequest",PageType);
i.putExtras(extras);
startActivityForResult(i,100);
//i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
}
});
ivAttachment2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(strPhoto2 == "" && PageType.equals("NewRequestMedical")) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
photoTemp = "photo2";
}
else if(strPhoto2 == "" && !PageType.equals("NewRequestMedical"))
{
Toast.makeText(getApplicationContext(), "there is no attachment on this request",
Toast.LENGTH_SHORT).show();
}
else
{
Intent i = new Intent(MedicalClaim.this, DetailPhotoMedical.class);
/* i.putExtra("photo", strPhoto2);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);*/
Bundle extras = new Bundle();
extras.putString("photo", strPhoto2);
extras.putString("photoNo","photo2");
extras.putString("PageTypeRequest",PageType);
i.putExtras(extras);
startActivityForResult(i,100);
}
}
});
ivAttachment3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(strPhoto3 == "" && PageType.equals("NewRequestMedical")) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
photoTemp = "photo3";
}
else if(strPhoto3 == "" && !PageType.equals("NewRequestMedical"))
{
Toast.makeText(getApplicationContext(), "there is no attachment on this request",
Toast.LENGTH_SHORT).show();
}else
{
Intent i = new Intent(MedicalClaim.this, DetailPhotoMedical.class);
Bundle extras = new Bundle();
extras.putString("photo", strPhoto3);
extras.putString("photoNo","photo3");
extras.putString("PageTypeRequest",PageType);
i.putExtras(extras);
startActivityForResult(i,100);
/*i.putExtra("photo", strPhoto3);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);*/
}
}
});
ivAttachment4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(strPhoto4 == "" && PageType.equals("NewRequestMedical")) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
photoTemp = "photo4";
}
else if(strPhoto4 == "" && !PageType.equals("NewRequestMedical"))
{
Toast.makeText(getApplicationContext(), "there is no attachment on this request",
Toast.LENGTH_SHORT).show();
}else
{
Intent i = new Intent(MedicalClaim.this, DetailPhotoMedical.class);
Bundle extras = new Bundle();
extras.putString("photo", strPhoto4);
extras.putString("photoNo","photo4");
extras.putString("PageTypeRequest",PageType);
i.putExtras(extras);
startActivityForResult(i,100);
/* i.putExtra("photo", strPhoto4);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);*/
}
}
});
ivAttachment5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(strPhoto5 == "" && PageType.equals("NewRequestMedical")) {
Intent galleryIntent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(galleryIntent, RESULT_LOAD_IMAGE);
photoTemp = "photo5";
}
else if(strPhoto5 == "" && !PageType.equals("NewRequestMedical"))
{
Toast.makeText(getApplicationContext(), "there is no attachment on this request",
Toast.LENGTH_SHORT).show();
}
else{
Intent i = new Intent(MedicalClaim.this, DetailPhotoMedical.class);
Bundle extras = new Bundle();
extras.putString("photo", strPhoto5);
extras.putString("photoNo","photo5");
extras.putString("PageTypeRequest",PageType);
i.putExtras(extras);
startActivityForResult(i,100);
/* i.putExtra("photo", strPhoto5);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);*/
}
}
});
now i just make 10 imageviews and declare all. which is not dynamic. and i convert the photo to bitmap and it will be send to database.
is there any way or library that i can use?
You can have a "Add Image" button like below instead of having multiple images.
Then on "add image" button click you can hit gallery intent with startactivityforresults() for getting the images and onAcivityResult() you can create imageView and add it to container and upload the same.
public void addImageView(Context context, View container){
ImageView imgNew = new ImageView(context);
//add layout params & set image
container.addView(newImage);
// start service to upload the image
}

Extract json string i.e authentication Token from Json response for next activity.

*on postExecute()
#Override
protected void onPostExecute(String s) {
if (s != null) {
s.replaceAll("\\s+","");
Log.e("Fetch_frame_response", s);
userToken = s.substring(24,451);
Log.e("userToken", userToken);
Intent abc = new Intent(MainActivity.this, Orderlist.class);
startActivity(abc);
finish();
} else {
Intent abc = new Intent(MainActivity.this, MainActivity.class);
startActivity(abc);
Toast.makeText(MainActivity.this, "Invalid credentials", Toast.LENGTH_LONG).show();
}
}
}
}
*logcat Response which is not fetching me the value i want to stored as a variable userToken
07-29 10:30:57.556 7341-7341/com.example.rinzinchoephel.driverdemo2 E/userToken: 2791d970-c11d-48f6-92f3-8ec4f0b14820","contactEmail":"rchomphel#gmail.com","contactPhones":"+19731488021","createdAt":"2016-07-04T01:42:11.452-05:00","description":"","email":"rchomphel#gmail.com","id":"577a051469702d0380170000","internalId":"rinzin","lastAccessedOn":"2016-07-04T01:42:11.452-05:00","name":"rinzin choephel","phone":"+19731488021","updatedAt":"2016-07-04T01:42:11.452-05:00","userType":"merchant","username":"r
Try this:
#Override
protected void onPostExecute(String s) {
if (s != null) {
Log.e("Fetch_frame_response", s);
try {
JSONObject object=new JSONObject(s);
String userToken=object.getString("authenticationToken");
Log.e("userToken",userToken);
} catch (JSONException e) {
e.printStackTrace();
}
Intent abc = new Intent(MainActivity.this, Orderlist.class);
startActivity(abc);
finish();
} else {
Intent abc = new Intent(MainActivity.this, MainActivity.class);
startActivity(abc);
Toast.makeText(MainActivity.this, "Invalid credentials", Toast.LENGTH_LONG).show();
}
}
}
}
In you postexecute
You must parse your json dont use substring
#Override
protected void onPostExecute(String s) {
if (s != null) {
try {
JSONObject responseObject = new JSONObject(s);
int status = responseObject.getInt("status");
String message =responseObject.getString("message");
if(status == 1){
String UserToken = responseObject.getString("userToken");
Log.i("userToken",UserToken );
Intent abc = new Intent(MainActivity.this, Orderlist.class);
abc.putExtra("userToken",UserToken);
startActivity(abc);
finish();
Toast.makeText(context,message,Toast.LENGTH_LONG).show();
}else if(status ==2){
Toast.makeText(context,message,Toast.LENGTH_LONG).show();
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Intent abc = new Intent(MainActivity.this, MainActivity.class);
startActivity(abc);
Toast.makeText(MainActivity.this, "Invalid credentials", Toast.LENGTH_LONG).show();
}
}
}
}
Note: Use SharedPrefernce to store your user data so that is can be accessed from anywhere

Data is not passing through intent

I want to send the integer value from one activity to another but I am not getting the value,There is no error in my project.If I am giving the static value it is working so problem with intent only..
Passing the data
try {
JSONObject jsonobject = new JSONObject(doc);
final String statusCode=jsonobject.get("code").toString();
System.out.print("Code......>>>>>>>>>>>>>>"+statusCode);
switch (statusCode){
case "400":
Toast.makeText(getApplicationContext(), "" + doc, Toast.LENGTH_LONG).show();
break;
case "200":
final Dialog dialog = new Dialog(SecondActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.link_dialog);
Button dialogButtonCustomercare = (Button) dialog
.findViewById(R.id.button_ok);
Button dialogButtonCustomer = (Button) dialog
.findViewById(R.id.button_contact_us);
dialogButtonCustomercare.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), SecondActivity.class);
i.putExtra("StatusCode", 200);
startActivity(i);
// dialog.dismiss();
}
});
dialogButtonCustomer.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
makeCall(phonenumber);
}
});
dialog.show();
break;
default:
Toast.makeText(getApplicationContext(), "Oops something went wrong! ", Toast.LENGTH_LONG).show();
break;
}
} catch (Exception e) {
Log.i("Error", e.getMessage());
}
Getting the data
int responseCode ;
Intent i = getIntent();
responseCode = i.getIntExtra("StatusCode",0);
System.out.print("Status Code" + responseCode);
if (responseCode==200) {
DetailsImageView.setVisibility(View.VISIBLE);
// textview.settext(bank details verification done)
} else {
DetailImageView.setVisibility(View.INVISIBLE);
}
dialogButtonOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(getApplicationContext(), SecondActivity.class);
i.putExtra("StatusCode", 200);
// Toast.makeText(getApplicationContext(), "sucessful intent" +200, Toast.LENGTH_LONG).show();
startActivity(i);
finish();
dialog.dismiss();
}
});

Image is not being displayed in child activity

Here, I have to select an image from gallery or camera. When user selects image from gallery, that selected image should be displayed to next activity. But here these both activities are under the same tab, say tab A. Means in tab A there are two activities. In first activity, user has two options to select image either from gallery or from camera. And in second activity under same tab A, user gets that selected image. But here I'm not getting the expected output. Below is my code...
MainActivity.java
public class MainActivity extends TabActivity {
TabHost tabHost;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources ressources = getResources();
tabHost = getTabHost();
Intent intentProfile = new Intent().setClass(this, Tab1.class);
TabSpec tabProfile = tabHost
.newTabSpec("Profile")
.setIndicator("Profile", ressources.getDrawable(R.drawable.ic_launcher))
.setContent(intentProfile);
Intent intentFriends = new Intent().setClass(this, Tab2.class);
TabSpec tabFriends = tabHost
.newTabSpec("Friends")
.setIndicator("Friends", ressources.getDrawable(R.drawable.ic_launcher))
.setContent(intentFriends);
tabHost.addTab(tabProfile);
tabHost.addTab(tabFriends);
tabHost.setCurrentTab(0);
}
public void switchTabBar(int tab) {
tabHost.setCurrentTab(tab);
}
#Override
public void onBackPressed() {
// Called by children
MainActivity.this.finish();
}
}
ABCGroup.java
public class ABCGroup extends ActivityGroup{
public static ABCGroup group;
private ArrayList<View> history;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.history = new ArrayList<View>();
group = this;
View view = getLocalActivityManager().startActivity
("ParentActivity",
new Intent(ABCGroup.this, Tab1.class)
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
replaceView(view);
}
public void replaceView(View v) {
// Adds the old one to history
history.add(v);
// Changes this Groups View to the new View.
setContentView(v);
}
public void back() {
if(history.size() > 0) {
history.remove(history.size()-1);
if(history.size()<=0){
finish();
}else{
setContentView(history.get(history.size()-1));
}
}else {
finish();
}
}
#Override
public void onBackPressed() {
ABCGroup.group.back();
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if (keyCode == KeyEvent.KEYCODE_BACK){
ABCGroup.group.back();
return true;
}
return super.onKeyDown(keyCode, event);
}
}
Tab1.java
public class Tab1 extends ActivityGroup {
Button gallery, camera;
private ArrayList<View> myActivityHistory;
private static final int REQUEST_ID = 1;
private static final int HALF = 2;
private static final int TAKE_PICTURE = 3;
private Uri mUri;
private Bitmap mPhoto;
int i = 0;
#SuppressWarnings("deprecation")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab1);
myActivityHistory = new ArrayList<View>();
gallery = (Button)findViewById(R.id.gallery);
camera = (Button)findViewById(R.id.camera);
gallery.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
Intent intent = new Intent();
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, REQUEST_ID);
}
});
camera.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
File f = new File(Environment.getExternalStorageDirectory(), "photo.jpg");
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
mUri = Uri.fromFile(f);
startActivityForResult(i, TAKE_PICTURE);
}
});
}
public void replaceContentView(String id, Intent newIntent, int flag)
{
View mview = getLocalActivityManager().startActivity(id,newIntent.addFlags(flag)).getDecorView();
ABCGroup.group.replaceView(mview);
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case TAKE_PICTURE:
if (resultCode == Activity.RESULT_OK)
{
getContentResolver().notifyChange(mUri, null);
ContentResolver cr = getContentResolver();
try
{
mPhoto = null;
mPhoto = android.provider.MediaStore.Images.Media.getBitmap(cr, mUri);
Uri selectedImageUri = data.getData();
String selectedImagePath = getPath(selectedImageUri);
}
catch (Exception e)
{
Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
break;
case REQUEST_ID :
InputStream stream = null;
if (resultCode == Activity.RESULT_OK) {
try
{
stream = getContentResolver().openInputStream(data.getData());
Bitmap original;
original = null;
original= BitmapFactory.decodeStream(stream);
Uri selectedImageUri = data.getData();
String selectedImagePath = getPath(selectedImageUri);
Intent in = new Intent(Tab1.this, Second.class);
replaceContentView("activity3", in, Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
catch (Exception e)
{
e.printStackTrace();
}
if (stream != null) {
try {
stream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
break;
}
}
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
Toast.makeText(getBaseContext(), "" + cursor.getString(column_index) , 5000).show();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
SharedPreferences.Editor editor = preferences.edit();
editor.putString("data", cursor.getString(column_index) );
editor.commit();
return cursor.getString(column_index);
}
}
Second.java
public class Second extends ActivityGroup {
public static Bitmap bmp;
String path;
ImageView iv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
Button btn = (Button)findViewById(R.id.button1);
iv = (ImageView)findViewById(R.id.imageView1);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
path = preferences.getString("data", "");
File imgFile = new File(path);
if(imgFile.exists()){
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
iv.setImageBitmap(myBitmap);
}
btn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
ABCGroup.group.back();
}
});
}
#Override
public void onBackPressed() {
// this.getParent().onBackPressed();
Intent intent = new Intent(Second.this, Tab1.class);
Tab1 parentActivity = (Tab1)getParent();
parentActivity.replaceContentView("Profile", new Intent(Second.this, Tab1.class), Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
}

Categories

Resources