I am using metaio sdk. I am trying to simply toggle the visibility of two imageviews when pressing a button but it is not working.
My layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ma_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#00000000" >
-----
<ImageView
android:id="#+id/zoomIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="4dp"
android:layout_marginRight="4dp"
android:background="#drawable/zooming"
android:onClick="seeZoom" />
<ImageView
android:id="#+id/scrollerBg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/scrollerbg"
android:visibility="invisible"/>
<ImageView
android:id="#+id/scroller"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="#drawable/scroller"
android:visibility="invisible"/>
---
</RelativeLayout>
My code:
import android.view.MotionEvent;
import java.util.List;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import com.metaio.sdk.jni.IGeometry;
import com.metaio.sdk.jni.IMetaioSDKAndroid;
import com.metaio.sdk.jni.Vector3d;
import android.os.Environment;
import com.metaio.sdk.ARViewActivity;
import com.metaio.sdk.jni.EPLAYBACK_STATUS;
import com.metaio.sdk.jni.IMetaioSDKCallback;
import com.metaio.sdk.jni.MovieTextureStatus;
import com.metaio.sdk.jni.Rotation;
import com.metaio.sdk.MetaioDebug;
import com.company.abc.R;
public class MainActivity extends ARViewActivity
{
public RelativeLayout mGUIView;
//public ImageView imgView1;
//public ImageView imgView2;
Camera camera;
private IGeometry tdp1, tdp2, tdp3, tdp4, tdp5, tdp6, tdp7, sal1, sal2;
boolean isTorchOn=false;
Parameters camParams;
public ImageView basePng;
public ImageView zoomIcon;
ImageView scroller;
public LayoutParams scrollerParams;
ImageView scrollerBg;
public LayoutParams scrollerBgParams;
boolean afc;
int counter;
int displayWidthbyTwo;
int displayHeightbyTwo;
int scrollerW;
int scrollerH;
int scrollerBgW;
int scrollerBgH;
int ZoomValue=0;
int maxZoomLevel;
int maxZoombyfour;
boolean zoomSupported;
boolean isZoomBarVisible=false;
private MetaioSDKCallbackHandler mCallbackHandler;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
MetaioDebug.enableLogging(true);
mCallbackHandler = new MetaioSDKCallbackHandler();
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
displayWidthbyTwo=metrics.widthPixels/2;
displayHeightbyTwo=metrics.heightPixels/2;
PackageManager PM= this.getPackageManager();
afc = PM.hasSystemFeature(PackageManager.FEATURE_CAMERA_AUTOFOCUS);
setContentView(R.layout.mainactivity);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mGUIView = (RelativeLayout) getLayoutInflater().inflate(R.layout.mainactivity, null);
zoomIcon = (ImageView) mGUIView.findViewById(R.id.zoomIcon);
scroller = (ImageView) mGUIView.findViewById(R.id.scroller);
scrollerBg = (ImageView) mGUIView.findViewById(R.id.scrollerBg);
scroller.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
scrollerW = scroller.getMeasuredWidth()/2;
scrollerH = scroller.getMeasuredHeight()/2;
scrollerParams = (LayoutParams) scroller.getLayoutParams();
scrollerParams.topMargin = displayHeightbyTwo-150-scrollerH;
scroller.setLayoutParams(scrollerParams);
scrollerBg.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
scrollerBgW = scrollerBg.getMeasuredWidth()/2;
scrollerBgH = scrollerBg.getMeasuredHeight()/2;
scrollerBgParams = (LayoutParams) scrollerBg.getLayoutParams();
scrollerBgParams.topMargin = displayHeightbyTwo-scrollerBgH;
scrollerBg.setLayoutParams(scrollerBgParams);
scroller.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
LayoutParams layoutParams = (LayoutParams) scroller.getLayoutParams();
switch(event.getAction())
{
case MotionEvent.ACTION_MOVE:
//Get y coord of the touch point relative to screen
int y_cord = (int) event.getRawY();
//Restrict scroller bewtween center of screen +- 150
if(y_cord>(displayHeightbyTwo+150))
y_cord = displayHeightbyTwo+150;
if(y_cord<(displayHeightbyTwo-150))
y_cord = displayHeightbyTwo-150;
//Set zoom levels at various steps
if(y_cord<=displayHeightbyTwo-90){
camParams.setZoom(0);
Log.i("Zooming:","0");
ZoomValue=0;}
if(y_cord<=displayHeightbyTwo-30 && y_cord>displayHeightbyTwo-90){
camParams.setZoom(maxZoombyfour);
Log.i("Zooming:","1");
ZoomValue=1;}
if(y_cord<=displayHeightbyTwo+30 && y_cord>displayHeightbyTwo-30){
camParams.setZoom(maxZoombyfour*2);
Log.i("Zooming:","2");
ZoomValue=2;}
if(y_cord<=displayHeightbyTwo+90 && y_cord>displayHeightbyTwo+30){
camParams.setZoom(maxZoombyfour*3);
Log.i("Zooming:","3");
ZoomValue=3;}
if(y_cord>displayHeightbyTwo+90){
camParams.setZoom(maxZoomLevel);
Log.i("Zooming:","4");
ZoomValue=4;}
camera.setParameters(camParams);
scrollerParams.topMargin = y_cord-scrollerH;
scroller.setLayoutParams(scrollerParams);
break;
default:
break;
}
return true;
}
});
}
#Override
protected int getGUILayout()
{
// TODO: return 0 in case of no GUI overlay
return R.layout.mainactivity;
}
#Override
protected void onStart()
{
super.onStart();
// hide GUI until SDK is ready
//if (!mRendererInitialized)
//mGUIView.setVisibility(View.GONE);
// add GUI layout
addContentView(mGUIView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
}
#Override
protected void loadContents()
{
// Load desired tracking data for planar marker tracking
String Path = "storage/sdcard1/AS/tdp/";
//final String trackingConfigFile = AssetsManager.getAssetPath("Tracking.xml");
boolean result = metaioSDK.setTrackingConfiguration(Path+"Tracking.xml");
String movie1Path = Path + "movie1.3gp";
tdp1 = metaioSDK.createGeometryFromMovie(movie1Path, false) ;
tdp1.setCoordinateSystemID(1);
tdp1.setScale(new Vector3d(4.0f,4.0f,4.0f));
tdp1.startMovieTexture(true); // loop = true;
}
#Override
protected void onGeometryTouched(IGeometry geometry) {
// TODO Auto-generated method stub
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
}
#Override
public void onSurfaceChanged(int width, int height) {
//always call the super implementation first
super.onSurfaceChanged(width, height);
camera=IMetaioSDKAndroid.getCamera(this);
camParams = camera.getParameters();
if(afc){
List<String> focusModes = camParams.getSupportedFocusModes();
if(focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE))
camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
else if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO))
camParams.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
camera.setParameters(camParams);
}
if(camParams.isZoomSupported()){
this.runOnUiThread(new Runnable(){
public void run(){
zoomIcon.setVisibility(View.VISIBLE);
}
});
maxZoomLevel = camParams.getMaxZoom();
maxZoombyfour = Math.round(maxZoomLevel/4);
zoomSupported=true;
}
}
#Override
protected IMetaioSDKCallback getMetaioSDKCallbackHandler()
{
return mCallbackHandler;
}
final class MetaioSDKCallbackHandler extends IMetaioSDKCallback
{
}
public void showTorch(View v) {
if(isTorchOn){
IMetaioSDKAndroid.stopTorch(this);
isTorchOn=false;
}
else{
IMetaioSDKAndroid.startTorch(this);
isTorchOn=true;
}
}
public void seeZoom(View v) {
if(isZoomBarVisible){
scroller.setVisibility(0);
//scrollerBg.setVisibility(View.INVISIBLE);
isZoomBarVisible=false;
Log.i("ss","ss");
}
else{
scroller.setVisibility(1);
isZoomBarVisible=true;
Log.i("ss","ss");
}
}
public void seeSettings(View v) {
Intent intent = new Intent(this, Settings.class);
startActivity(intent);
//finish();
}
public void seeCatalog(View v) {
Intent intent = new Intent(this, CatalogueActivity.class);
startActivity(intent);
//finish();
}
}
I am trying in multiple ways since hours but none of them work . plesae tell me how to access the views from xml. This code used to work previously but it is not working now. Android programming really seems frustrating.
Thanks in advance
You must use setContent(R.layout.your_layout); inside onCreate
Like this
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//mGUIView = (RelativeLayout) getLayoutInflater().inflate(R.layout.scan, null);
setContent(R.layout.your_layout);
scroller = (ImageView) mGUIView.findViewById(R.id.scroller);
scrollerBg = (ImageView) mGUIView.findViewById(R.id.scrollerBg);
}
I guess the error is at 'R',
All you need to do is import your package.R
Example
...
import com.yourpackage.yourappname.R; //Import this
#Override
public void onCreate(Bundle savedInstanceState) {
MetaioCloudPlugin.startJunaio(null, getApplicationContext());
super.onCreate(savedInstanceState);
setContentView(R.layout.mainactivity);
...
Then it should work fine :D
I encountered the same issue before. I managed to solve it by clearing the cache, data and uninstall the app from the device. It is working after I re-publish the app to the testing device. Maybe you could try it.
Related
I want to an images slider inside my app!
after a long search I found that I have to use a ViewPager to get things done!
I need to make the Viewpager to be come full screen when I select image and slides left and right to show previous and next image in the slider..
here's my code :
FullScreenFragment.java
package com.mustafataj.zoalvision.checkmyride.fragments;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.Button;
import com.mustafataj.zoalvision.checkmyride.R;
import com.mustafataj.zoalvision.checkmyride.adapter.SlidingImage_Adapter;
import com.viewpagerindicator.CirclePageIndicator;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import butterknife.ButterKnife;
public class FullScreenFragment extends Fragment implements Runnable {
View v;
ViewPager pager;
Button share;
private static final Integer[] IMAGES= {R.drawable.demo_car_thumb_4,R.drawable.demo_car_thumb_3,R.drawable.demo_car_thumb_2,R.drawable.demo_car_thumb_1};
private ArrayList<Integer> ImagesArray = new ArrayList<Integer>();
public FullScreenFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
v = inflater.inflate(R.layout.fragment_full_screen, container, false);
//pager = v.findViewById(R.id.pager);
share = v.findViewById(R.id.share);
// pager.setAdapter(new SlidingImage_Adapter(getActivity(),ImagesArray));
init();
share.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent share = new Intent(Intent.ACTION_SEND);
share.setType("image/jpeg");
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
File f = new File(Environment.getExternalStorageDirectory()+File.separator +"thumb.jpg");
try {
f.createNewFile();
FileOutputStream fo = new FileOutputStream(f);
fo.write(bytes.toByteArray());
} catch (IOException e) {
e.printStackTrace();
}
share.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://sdcard/temp/jpg"));
startActivity(Intent.createChooser(share,"Share Image to ..."));
}
});
return v;
}
private void init() {
for(int i=0;i<IMAGES.length;i++)
ImagesArray.add(IMAGES[i]);
pager = (ViewPager) v.findViewById(R.id.pager);
pager.setAdapter(new SlidingImage_Adapter(getActivity(),ImagesArray));
}
#Override
public void onDestroy () {
super.onDestroy();
if (Build.VERSION.SDK_INT > 10) {
unregisterSystemUiVisibility();
}
exitFullscreen(getActivity());
}
public static boolean isImmersiveAvailable() {
return android.os.Build.VERSION.SDK_INT >= 19;
}
public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus) {
_handler.removeCallbacks(this);
_handler.postDelayed(this, 300);
} else {
_handler.removeCallbacks(this);
}
}
public void onKeyDown(int keyCode) {
if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
_handler.removeCallbacks(this);
_handler.postDelayed(this, 500);
}
}
#Override
public void onStop() {
_handler.removeCallbacks(this);
super.onStop();
}
#Override
public void run() {
setFullscreen();
}
public void setFullscreen() {
setFullscreen(getActivity());
}
public void setFullscreen(Activity activity) {
if (Build.VERSION.SDK_INT > 10) {
int flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_FULLSCREEN;
if (isImmersiveAvailable()) {
flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
}
activity.getWindow().getDecorView().setSystemUiVisibility(flags);
} else {
activity.getWindow()
.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}
public void exitFullscreen(Activity activity) {
if (Build.VERSION.SDK_INT > 10) {
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
} else {
activity.getWindow()
.setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
}
private Handler _handler = new Handler();
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void registerSystemUiVisibility() {
final View decorView = getActivity().getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
#Override
public void onSystemUiVisibilityChange(int visibility) {
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
setFullscreen();
}
}
});
}
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void unregisterSystemUiVisibility() {
final View decorView = getActivity().getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener(null);
}}
and this my adapter class:
SlidingImage_Adapter.java:
package com.mustafataj.zoalvision.checkmyride.adapter;
import android.content.Context;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.mustafataj.zoalvision.checkmyride.R;
import java.util.ArrayList;
/**
* Created by Shashoug on 02/07/18.
*/
public class SlidingImage_Adapter extends PagerAdapter {
private ArrayList<Integer> IMAGES ;
private LayoutInflater inflater;
private Context context;
public SlidingImage_Adapter(Context context,ArrayList<Integer> IMAGES) {
this.context = context;
this.IMAGES=IMAGES;
inflater = LayoutInflater.from(context);
}
#Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((View) object);
}
#Override
public int getCount() {
return IMAGES.size();
}
#Override
public Object instantiateItem(ViewGroup view, int position) {
View imageLayout = inflater.inflate(R.layout.sliding_image_layout, view, false);
assert imageLayout != null;
final ImageView imageView = (ImageView) imageLayout
.findViewById(R.id.image);
imageView.setImageResource(IMAGES.get(position));
view.addView(imageLayout, 0);
return imageLayout;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view.equals(object);
}
#Override
public void restoreState(Parcelable state, ClassLoader loader) {
}
#Override
public Parcelable saveState() {
return null;
}}
and this my fragment_full_screen.xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/ms_black" tools:context="com.mustafataj.zoalvision.checkmyride.fragments.FullScreenFragmen">
<Button
android:layout_marginTop="15dp"
android:layout_marginRight="15dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:backgroundTint="#ED6326"
android:background="#drawable/ic_share"
android:id="#+id/share"
android:layout_width="30dp"
android:layout_height="30dp" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</android.support.v4.view.ViewPager>
</RelativeLayout>
Full_screen_viewer.xml :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mustafataj.zoalvision.checkmyride.fragments.FullScreenFragment">
<fragment
class="com.mustafataj.zoalvision.checkmyride.fragments.FullScreenFragment"
android:id="#+id/titles"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</FrameLayout>
and when I click to show the full screen fragment nothing popups without any errors?
how to fix that?
and If there any way to implement my idea feel free to guide me.
thanks in advance :)
Pageviewer.java code:
//hide status bar/action bar on single tap
package com.app.imageswiper;
import android.app.ActionBar;
import android.app.Dialog;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.support.design.widget.TabLayout;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v4.view.MotionEventCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
public class Pageviwer extends AppCompatActivity {
private Integer[] mImageIds = {R.drawable.page001, R.drawable.page002,
R.drawable.page003};
private static final String DEBUG_TAG = "pageviwer ";
ImageView imageView;
float startXValue = 1;
public int num;
public int click;
protected static final String TAG = "Pageviwer";
private GestureDetector mGestureDetector;
public SharedPreferences prefs;
public static int Bookmark = 0;
public static int Pageno = 0;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
prefs = PreferenceManager.getDefaultSharedPreferences(this);
int Bookmark1 = prefs.getInt("Bookmark", 0);
Bookmark = Bookmark1;
prefs = PreferenceManager.getDefaultSharedPreferences(this);
int Pageno1 = prefs.getInt("Pageno", 0);
Pageno = Pageno1;
setContentView(R.layout.pageviwer);
imageView = (ImageView) findViewById(R.id.image_place_holder);
imageView.setImageResource(mImageIds[0]);
TextView tv1 = (TextView) findViewById(R.id.pageno);
tv1.setText("" + (num + 1));
Toast.makeText(getApplicationContext(), "value is " + num, Toast.LENGTH_LONG).show();
setupGestureDetector();
hideActionBar(); // hide action bar after 1 second
}
private void setupGestureDetector() {
mGestureDetector = new GestureDetector(this,
new GestureDetector.SimpleOnGestureListener() {
//Detecting Swipe/Fling Direction
#Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
Log.i(TAG, "onFling");
if (e1.getX() < e2.getX()) {
Log.d(TAG, "Left to Right swipe performed");
if (num == 2) {
num = num;
} else {
imageView.setImageResource(mImageIds[num + 1]);
num = num + 1;
}
TextView tv1 = (TextView) findViewById(R.id.pageno);
tv1.setText("" + (num + 1));
Toast.makeText(getApplicationContext(), "value is " + num, Toast.LENGTH_LONG).show();
}
if (e1.getX() > e2.getX()) {
Log.d(TAG, "Right to Left swipe performed");
if (num == 0) {
num = num;
} else {
imageView.setImageResource(mImageIds[num - 1]);
num = num - 1;
}
TextView tv1 = (TextView) findViewById(R.id.pageno);
tv1.setText("" + (num + 1));
Toast.makeText(getApplicationContext(), "value is " + num, Toast.LENGTH_LONG).show();
}
return true;
}
//detecting single tap
#Override
public boolean onSingleTapUp(MotionEvent e) {
Log.i(TAG, "onSingleTapUp");
Toast.makeText(getApplicationContext(), "Single Tap ", Toast.LENGTH_LONG).show();
//Remove notification bar and action bar
if (click == 0) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
if (getSupportActionBar() != null) getSupportActionBar().hide();
click = 1;
}
//Return notification bar and action bar
else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
if (getSupportActionBar() != null) getSupportActionBar().show();
click = 0;
}
return true;
}
});
}
#Override
public boolean onTouchEvent(MotionEvent event) {
if (mGestureDetector != null) {
return mGestureDetector.onTouchEvent(event);
} else {
return super.onTouchEvent(event);
}
}
public void hideActionBar() {
Handler h = new Handler();
h.postDelayed(new Runnable() {
#Override
public void run() {
// DO DELAYED STUFF
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
if (getSupportActionBar() != null) getSupportActionBar().hide();
click = 1;
}
}, 1000); // 1000 milliseconds (1 second)
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == com.app.imageswiper.R.id.action_settings) {
Bookmark=1;
prefs.edit().putInt("Bookmark", Bookmark).commit();
prefs.edit().putInt("Pageno", num).commit();
Toast.makeText(getApplicationContext(), "Bookmark value is "+Bookmark, Toast.LENGTH_LONG).show();
}
return super.onOptionsItemSelected(item);
}
}
ViewPagerAdapter code:
package com.app.imageswiper;
/**
* Created by Jaffer on 14-Apr-16.
*/
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class Bookmarks extends Fragment {
public SharedPreferences prefs;
public static int Bookmark = 0;
public static int Pageno = 0;
Button sendButton = null;
View inflatedView = null;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
int Bookmark1 = prefs.getInt("Bookmark", 0);
Bookmark = Bookmark1;
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
int Pageno1 = prefs.getInt("Pageno", 0);
Pageno = Pageno1;
this.inflatedView = inflater.inflate(R.layout.bookmarks, container, false);
sendButton = (Button) inflatedView.findViewById(R.id.bookmark);
if(Bookmark==1){sendButton.setText("Page "+Pageno);}
else {sendButton.setText("No Bookmark ");}
if(sendButton == null)
{
Log.d("debugCheck", "HeadFrag: sendButton is null");
return inflatedView;
}
sendButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), Pageviwer.class);
startActivity(intent);
}
});
return inflatedView;
}
}
bookmarks.xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/bookmarks">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAllCaps="false"
style="#style/Widget.AppCompat.Button.Borderless"
android:id="#+id/bookmark"
android:layout_alignParentBottom="true" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#android:color/darker_gray"/>
</LinearLayout>
I don't know how to update the button text from Pageviewer.java for the button with R.id.bookmark that shows up on the Bookmarks fragment on the click of menu item R.id.action_settings. I want to do this so that the button text corresponds to the page that is being bookmarked. I tried alot of things but to no avail. Can someone please help me with anything?
Thanks in advance
Create a method in your fragment to update the text of your button.
public void updateText(String newText){
//assuming button is globally declared in your fragment.
button.setText(newText);
}
Instead of Gesture Detector you could use a ViewPager which supports swiping to the left and right.You can find a sample implementation here.
Then in your Activty,implement PageChanegListener on ViewPager.
viewPager.addOnPageChangeListener(new OnPageChangeListener() {
public void onPageScrollStateChanged(int state) {}
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
public void onPageSelected(int position) {
// Check if this is the page you want.You have to implement viewpager's adapter with getItem(index) which returns a fragment at that index.
BookMarkFragment fragment (BookMarkFragment)mAdapter.getItem(position);
fragment.updateText(newText);
};
});
You should save the state of a button somewhere. Your field int Bookmark == 0, so expression sendButton.setText("Page "+Pageno); never execute. Save the state in SharedPreferences and get this state. Like this:
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
int isBookmark = prefs.getInt("Bookmark", 0);
int mPageno = prefs.getInt("Pageno", 0);
...
if(isBookmark == 1){
sendButton.setText("Page " + mPageno);
} else {
sendButton.setText("No Bookmark");
}
I have a checkbox , I want it to be unchecked by default. i.e False.
On manually checking the checkbox, i.e if the checkbox is checked , it perform certain action in another class.
I tried to save the sate of the checkbox using SharedPreference, but when I tried to fetch the checkbox value in another class using GetBoolean , I am not getting the saved value.
my layout xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Number of Circle" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
</EditText>
<CheckBox
android:id="#+id/chkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/enable_touch_checkBox"
/>
<Button
android:id="#+id/buttonAlert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_marginTop="131dp"
android:text="save"
/>
</LinearLayout>
MyPreferenceActivity class
package de.vogella.android.wallpaper;
import android.app.Activity;
import android.app.WallpaperManager;
import android.content.ComponentName;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;
public class MyPreferencesActivity extends Activity {
private PrefManager pref;
private TextView txtGoogleUsername, txtNoOfCircles, txtGalleryName;
private CheckBox checkBox ;
private Button btnSave;
private Boolean checkBoxValue;
private static final String PREF_NAME = "wallpaper";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
txtNoOfCircles = (TextView) findViewById(R.id.editText1);
checkBox = (CheckBox) findViewById(R.id.chkBox1);
btnSave = (Button) findViewById(R.id.buttonAlert);
pref = new PrefManager(getApplicationContext());
txtNoOfCircles.setText(String.valueOf(pref.getNoOfGridCircles()));
//checkBox.setChecked(pref.getCheckBox());
/********************************/
SharedPreferences sharedPreferences =PreferenceManager.getDefaultSharedPreferences(this);
checkBoxValue = sharedPreferences.getBoolean("Box", false);
if(checkBoxValue){
checkBox.setChecked(true);
}
else
{
checkBox.setChecked(false);
}
/********************************/
/*saveLogin = pref.getCheckBox();
if(saveLogin == true){
checkBox.setChecked(true);
}*/
btnSave.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//savePreferences("Box", checkBox.isChecked());
if(checkBox.isChecked())
{
//pref.setCheckBox(true);
savePreferences("Box", checkBox.isChecked());
Toast.makeText(getApplicationContext(),
"hii",
Toast.LENGTH_LONG).show();
}
else
{
savePreferences("Box", checkBox.isChecked());
//pref.setCheckBox(false);
}
boolean vals = pref.getCheckBox();
//checkBox = (CheckBox) findViewById(R.id.chkBox1);
String no_of_columns = txtNoOfCircles.getText().toString()
.trim();
//checkBox.get
if (no_of_columns.length() == 0 || !isInteger(no_of_columns)) {
Toast.makeText(getApplicationContext(),
getString(R.string.toast_enter_valid_number),
Toast.LENGTH_LONG).show();
return;
}
if(no_of_columns != null || no_of_columns.equals(" ") )
{
if (!no_of_columns.equalsIgnoreCase(String.valueOf(pref
.getNoOfGridCircles()))) {
// User changed the settings
// save the changes and launch SplashScreen to initialize
// the app again
// pref.setGoogleUsername(googleUsername);
pref.setNoOfGridCircles(Integer.parseInt(no_of_columns));
// pref.setCheckBox(val);
// pref.setGalleryName(galleryName);
// start the app from SplashScreen
Intent i = new Intent(MyPreferencesActivity.this,
SetWallpaperActivity2.class);
// Clear all the previous activities
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(i);
} else {
// user not modified any values in the form
// skip saving to shared preferences
// just go back to previous activity
onBackPressed();
}
}
}
});
}
public boolean isInteger(String input) {
try {
Integer.parseInt(input);
return true;
} catch (Exception e) {
return false;
}
}
private void savePreferences(String key, boolean value){
//SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences sharedPreferences = getSharedPreferences(PREF_NAME,0);
Editor editor = sharedPreferences.edit();
editor.putBoolean(key, value);
editor.commit();
}
}
My wallpaperService class
package de.vogella.android.wallpaper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.animation.AnimatorSet.Builder;
import android.app.ActionBar.LayoutParams;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.net.Uri;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.service.wallpaper.WallpaperService;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.ContextThemeWrapper;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MyWallpaperService extends WallpaperService {
private final String TAG = getClass().getSimpleName();
private static final String PREF_NAME = "wallpaper";
//private PrefManager pref = new PrefManager(getApplicationContext());
#Override
public Engine onCreateEngine() {
Log.i( TAG, "onCreateEngine" );
return new MyWallpaperEngine();
}
private class MyWallpaperEngine<YourActivity> extends Engine {
private final Handler handler = new Handler();
private final Runnable drawRunner = new Runnable() {
#Override
public void run() {
draw();
}
};
private List<MyPoint> circles;
private Paint paint = new Paint();
Bitmap image = null;
private int width;
int height;
private boolean visible = true;
private int maxNumber;
private int maxNumber2;
private boolean touchEnabled;
private boolean touchEnabled2;
SharedPreferences prefs = null;
int fatchDataSize = 10;
ProdAdDetails []prodobj = new ProdAdDetails[fatchDataSize];
HashMap<Integer,String> map = new HashMap<Integer,String>();
Canvas canvas = null;
public MyWallpaperEngine()
{
pref= new PrefManager(getApplicationContext());
//prefs=PreferenceManager.getDefaultSharedPreferences(MyWallpaperService.this);
prefs = getSharedPreferences(PREF_NAME,0);
touchEnabled = prefs.getBoolean("Box",false);
}
#Override
public void onVisibilityChanged(boolean visible) {
this.visible = visible;
if (visible) {
handler.post(drawRunner);
} else {
handler.removeCallbacks(drawRunner);
}
}
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
this.visible = true;
handler.removeCallbacks(drawRunner);
}
#Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width,
int height) {
this.width = width;
this.height = height;
super.onSurfaceChanged(holder, format, width, height);
}
#Override
public void onTouchEvent(MotionEvent event) {
if (touchEnabled) {
if (event.getAction() == MotionEvent.ACTION_MOVE )
{
Toast.makeText(getApplicationContext(), "Move", Toast.LENGTH_SHORT).show();
}
else
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
Toast.makeText(getApplicationContext(), "Down", Toast.LENGTH_SHORT).show();
}
super.onTouchEvent(event);
} // if block end
}
private void draw() {
SurfaceHolder holder = getSurfaceHolder();
//Canvas canvas = null;
try {
canvas = holder.lockCanvas();
if (canvas != null) {
if (circles.size() >= maxNumber2) {
circles.clear();
map = new HashMap<Integer,String>();
}
int x = (int) (width * Math.random());
int y = (int) (height * Math.random());
circles.add(new MyPoint(null, String.valueOf(circles.size() + 1), x, y));
drawCircles(canvas, circles);
}
} finally {
if (canvas != null)
holder.unlockCanvasAndPost(canvas);
}
handler.removeCallbacks(drawRunner);
if (visible) {
handler.postDelayed(drawRunner, 10000);
}
}
// Surface view requires that all elements are drawn completely
private void drawCircles(Canvas canvas, List<MyPoint> circles) {
canvas.drawColor(Color.LTGRAY);
int i=0;
for (MyPoint point : circles) {
//-------------------------------
paint.setTextSize(20);
paint.setStrikeThruText(true);
image = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
canvas.drawBitmap(image, point.x, point.y, null);
//touchEnabled = ((SharedPreferences) paint).getBoolean("touch", true);
//=====================================
ProdAdDetails pad = prodobj[i];//(ProdAdDetails)point.prodobj;
String prodName = pad.getProd_name();
String prodDtl = pad.getProd_details();
String prodCompName = pad.getProd_comp_name();
String prodPrice = pad.getProd_price();
final String prodDtls = prodDtl+"\nCompany :"+prodCompName+"\nRate :"+prodPrice+"%";
canvas.drawText(prodName, point.x+1, point.y+1, paint);
canvas.drawBitmap(image, point.x, point.y, null);
int key = point.x;
System.out.println("put:::"+key);
map.put(key, prodDtls);
//-------------------------------
//canvas.drawPaint(paint);
//Circle(point.x, point.y, 40.0f, paint);
//Toast.makeText(getApplicationContext(), prodDtls, Toast.LENGTH_SHORT).show();
i++;
}
}
}
}
I have posted my code, any suggestion or advice will be of grate helpfull, as I am not able to understand where I am going wrong.
public static String KEY="Box";
private void savePreferences(boolean value){
SharedPreferences sharedpreferences = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();
editor.putBoolean(KEY,value);
editor.commit();
}
Retrieving End
SharedPreferences getpreferences = getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
boolean isChecked=getpreferences.getBoolean("Box",false);
OK so I'm using xml to set this menu which is supported by the following java code
package starting.rt;
import java.util.List;
import java.util.Random;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class Menu extends Activity implements OnClickListener{
View.OnTouchListener gestureListener;
TextView display;
Button begin;
Button random;
Button game;
TextView counter;
Button next;
Button previous;
Button moreapps;
Button rate;
Random myRandom;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(starting.rt.R.layout.menu);
begin = (Button) findViewById(starting.rt.R.id.Begin);
random = (Button) findViewById(starting.rt.R.id.Random);
display = (TextView) findViewById(starting.rt.R.id.tvResults);
counter = (TextView) findViewById(starting.rt.R.id.tvCounter);
next = (Button) findViewById(starting.rt.R.id.Next);
previous = (Button) findViewById(starting.rt.R.id.Previous);
moreapps = (Button)findViewById(R.id.More);
rate = (Button) findViewById(R.id.rate);
game = (Button) findViewById(R.id.game);
// display.setOnTouchListener(this.gestureListener);
begin.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent openStartingPoint = new Intent("starting.rt.RelationshipTipsActivity");
startActivity(openStartingPoint);
}});
moreapps.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent goToMarket;
goToMarket = new Intent(Intent.ACTION_VIEW, Uri.parse("market://search?q=pub:\"Wompa\""));
startActivity(goToMarket);
}});
game.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent openStartingPoint = new Intent("starting.rt.GameView");
startActivity(openStartingPoint);
}});
rate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse("market://details?id=" + getPackageName()));
startActivity(i);
}});}
public void onClick(View v) {
// TODO Auto-generated method stub
}
}
Now what's supposed to be happening is when they click on the game which starts a new java class called GameView it crashes on clicked. Every other button works.
This is the code from GameView
package starting.rt;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class GameView extends SurfaceView {
private GameLoopThread gameLoopThread;
private List<Sprite> sprites = new ArrayList<Sprite>();
private List<TempSprite> temps = new ArrayList<TempSprite>();
private long lastClick;
private Bitmap bmpBlood;
public GameView(Context context) {
super(context);
gameLoopThread = new GameLoopThread(this);
getHolder().addCallback(new SurfaceHolder.Callback() {
public void surfaceDestroyed(SurfaceHolder holder) {
boolean retry = true;
gameLoopThread.setRunning(false);
while (retry) {
try {
gameLoopThread.join();
retry = false;
} catch (InterruptedException e) {}
}
}
public void surfaceCreated(SurfaceHolder holder) {
createSprites();
gameLoopThread.setRunning(true);
gameLoopThread.start();
}
public void surfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
}
});
bmpBlood = BitmapFactory.decodeResource(getResources(), R.drawable.blood1);
}
private void createSprites() {
sprites.add(createSprite(R.drawable.bad1));
// sprites.add(createSprite(R.drawable.bad2));
// sprites.add(createSprite(R.drawable.bad3));
// sprites.add(createSprite(R.drawable.bad4));
// sprites.add(createSprite(R.drawable.bad5));
// sprites.add(createSprite(R.drawable.bad6));
// sprites.add(createSprite(R.drawable.good1));
// sprites.add(createSprite(R.drawable.good2));
// sprites.add(createSprite(R.drawable.good3));
// sprites.add(createSprite(R.drawable.good4));
// sprites.add(createSprite(R.drawable.good5));
// sprites.add(createSprite(R.drawable.good6));
}
private Sprite createSprite(int resouce) {
Bitmap bmp = BitmapFactory.decodeResource(getResources(), resouce);
return new Sprite(this, bmp);
}
#Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.BLACK);
for (int i = temps.size() - 1; i >= 0; i--) {
temps.get(i).onDraw(canvas);
}
for (Sprite sprite : sprites) {
sprite.onDraw(canvas);
}
}
#Override
public boolean onTouchEvent(MotionEvent event) {
if (System.currentTimeMillis() - lastClick > 300) {
lastClick = System.currentTimeMillis();
float x = event.getX();
float y = event.getY();
synchronized (getHolder()) {
for (int i = sprites.size() - 1; i >= 0; i--) {
Sprite sprite = sprites.get(i);
if (sprite.isCollition(x, y)) {
sprites.remove(sprite);
temps.add(new TempSprite(temps, this, x, y, bmpBlood));
break;
}
}
}
}
return true;
}
}
The GameView calls a few other classes for things part of the game but it crashes before it can start. I think it's crashing because it's switching from xml layout to the java surfaceview. Help would be appreciated :) Thanks!
First of all, you should always post in your questions the stacktrace with the exception from the Logcat if your app crashes.
You can't start a SurfaceView directly, instead your custom SurfaceView must be embedded in an Activity like any other view in android. For example:
public class GameViewActivity extends Activity {
#Override
public void onCreate(Bundle savedInstance) {
super.onCreate(savedInstance);
setContentView(new GameView(this));
}
}
I have search and could seem to find anything close to the issue I am having so I figured I would ask.
I have a Dashboard layout
This is all working correctly
What I want to do is have it work as shown below ( I have the Tabhost defined but I had to setup the class to extend TabActivity which breaks the ActionBar navigation )
The tabs correctly switch but it will not allow me to use any of the buttons on the action bar, and its not pulling the information correctly like it should be
the above works correctly. So I guess my question is how can I correctly add the TabHost to my classes and also have it Extend or Implement the Dashboard code? I have tried extends TabActivity implements Dashboard with no luck.
Here is my code thus far
Dashboard.java
package com.ondrovic.bbym;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
public abstract class Dashboard extends Activity {
public static final boolean usePrettyGoodSolution = false;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void onDestroy() {
super.onDestroy();
}
public void onPause() {
super.onPause();
}
public void onRestart() {
super.onRestart();
}
public void onResume() {
super.onResume();
}
public void onStart() {
super.onStart();
}
public void onStop() {
super.onStop();
}
public void onClickHome(View v) {
goHome(this);
}
public void onClickUpdate(View v) {
//startActivity(new Intent(getApplicationContext(), Update.class));
}
public void onClickAbout(View v) {
//startActivity(new Intent(getApplicationContext(), About.class));
}
public void goHome(Context context) {
final Intent intent = new Intent(context, Home.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
context.startActivity(intent);
}
#Override
public void setContentView(int layoutID) {
if (!usePrettyGoodSolution) {
super.setContentView(layoutID);
return;
}
Configuration c = getResources().getConfiguration();
int size = c.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK;
boolean isLarge = (size == Configuration.SCREENLAYOUT_SIZE_LARGE);
boolean isXLarge = (size == Configuration.SCREENLAYOUT_SIZE_XLARGE);
boolean addFrame = isLarge || isXLarge;
// if (isLarge) System.out.println ("Large screen");
// if (isXLarge) System.out.println ("XLarge screen");
int finalLayoutId = addFrame ? R.layout.large : layoutID;
super.setContentView(finalLayoutId);
if (addFrame) {
LinearLayout frameView = (LinearLayout) findViewById(R.id.frame);
if (frameView != null) {
// If the frameView is there, inflate the layout given as an
// argument.
// Attach it as a child to the frameView.
LayoutInflater li = ((Activity) this).getLayoutInflater();
View childView = li.inflate(layoutID, null);
if (childView != null) {
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT, 1.0F);
frameView.addView(childView, lp);
// childView.setBackgroundResource (R.color.background1);
}
}
}
}
public void setTitleFromActivityLabel(int textViewID) {
TextView tv = (TextView) findViewById(textViewID);
if (tv !=null) {
tv.setText(getTitle());
}
}
}
Individual.java
package com.ondrovic.bbym;
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class Individual extends TabActivity {
public void onCreate(Bundle savedSate) {
super.onCreate(savedSate);
setContentView(R.layout.individual);
TabHost tabHost = getTabHost();
TabSpec attspec = tabHost.newTabSpec("ATT");
attspec.setIndicator("AT&T", getResources().getDrawable(R.drawable.icons_att_tab));
Intent attIntent = new Intent(this, Individual_ATT.class);
attspec.setContent(attIntent);
TabSpec sprspec = tabHost.newTabSpec("SPRINT");
sprspec.setIndicator("SPRINT", getResources().getDrawable(R.drawable.icons_sprint_tab));
Intent sprIntent = new Intent(this, Individual_SPRINT.class);
sprspec.setContent(sprIntent);
TabSpec vzwspec = tabHost.newTabSpec("VERIZON");
vzwspec.setIndicator("VERIZON", getResources().getDrawable(R.drawable.icons_verizon_tab));
Intent vzwIntent = new Intent(this, Individual_VERIZON.class);
vzwspec.setContent(vzwIntent);
tabHost.addTab(attspec);
tabHost.addTab(sprspec);
tabHost.addTab(vzwspec);
}
}
Here is my individual.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/background1"
android:orientation="vertical" >
<include layout="#layout/title_bar" />
<include layout="#layout/tabs" />
</LinearLayout>
If there is any other code that needs to be post please let me know and thanks for the assistance
So I figured it out by doing the following. Even though there is probably a better way here is what I've got
Individual.java
package com.ondrovic.bbym;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class Individual extends Dashboard {
TabHost mTabs;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.individual);
setTitleFromActivityLabel(R.id.title_text);
mTabs = (TabHost) findViewById(android.R.id.tabhost);
LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
mLocalActivityManager.dispatchCreate(savedInstanceState);
mTabs.setup(mLocalActivityManager);
TabSpec attspec = mTabs.newTabSpec("ATT");
attspec.setIndicator("AT&T", getResources().getDrawable(R.drawable.icons_att_tab));
Intent attIntent = new Intent(this, Individual_ATT.class);
attspec.setContent(attIntent);
TabSpec sprintspec = mTabs.newTabSpec("SPRINT");
sprintspec.setIndicator("SPRINT", getResources().getDrawable(R.drawable.icons_sprint_tab));
Intent sprintIntent = new Intent(this, Individual_SPRINT.class);
sprintspec.setContent(sprintIntent);
TabSpec verizonspec = mTabs.newTabSpec("VERIZON");
verizonspec.setIndicator("VERIZON", getResources().getDrawable(R.drawable.icons_verizon_tab));
Intent verizonIntent = new Intent(this, Individual_ATT.class);
verizonspec.setContent(verizonIntent);
mTabs.addTab(attspec);
mTabs.addTab(sprintspec);
mTabs.addTab(verizonspec);
}
}
Here's the result everything is working :-)