How to hide navigation bar on android - android

I need to enable full screen mode without navigation bar on android which placed in the bootom of the screen. (Like on clash of clans game).
I don't know how can I do this in cocos2dx. Kindly suggest.

if your question about android then that is the answer
public class FullScreen extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
if you want full screen For window (Ex: web view .....)
int width = [[NSScreen mainScreen] frame].size.width;
int height = [[NSScreen mainScreen] frame].size.height;
[yourWindow setFrame:NSMakeRect(0, 0, width, height) display:YES];
You can refer to some tutorial teach you how make your window full screen
tutorial-making-your-mac-app-support-full-screen-in-1-minute.html
ios-7-tutorial-series-gestures-and-fullscreen-layouts
https://www.youtube.com/watch?v=Bb2ywxOnFZE

Related

How do I change the position of my new Activity (Display Metrics)

EDIT: The application's interface
I've created a Pop-up window and class that when I click this onInfoWindowClick in the google maps, a pop-up window will appear OR the next activity will appear. I used Display Metrics for this but it only shows up in the center screen.
What I want to happen is: when the activity shows up, I would like it to show up in the upper-top or at least have the power to change the position of the activity in any part of the window.
My problem: The display metrics shows the activity only in the center.
My codes in my Pop-Up window:
public class PopUp extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pop_layout);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setLayout((int)(width*.8),(int)(height*.5));
}
}
Note: Is there an another method to do this? Can you give me link on how to do it. (Only if there is an another method to do it)
Just add this line at the end:
getWindow().setGravity(Gravity.TOP);
P.S. you can use other values (not only Gravity.TOP) according to your needs. Also you can combine multiple options, for instance, getWindow().setGravity(Gravity.TOP|Gravity.START);

Draw overlay behind or over navigation bar

I'm creating an app which should draw fullscreen overlay. Something like lockscreen. The user set some timer and when time is come this overlay should appear.
But overlay doesn't cover system navigation bar. It's a problem when navigation bar is semi-transparent. User can touch system buttons and can see some changeable background behind them. Thus user can see something behind the lock screen. It's a problem.
How could I prevent this situation?
Notice that lock screen overlay is not the activity. User sets timer and can browse his device freely. When the time comes the app draws some view over the screen, like this:
View overlayView = new OverlayView(this);
windowManager.addView(overlayView, OverlayView.createLayoutParams(retrieveScreenHeight()));
where
public OverlayView(Context context) {
super(context);
inflate(context, R.layout.overlay_view, this);
}
static WindowManager.LayoutParams createLayoutParams(int height) {
final WindowManager.LayoutParams params =
new WindowManager.LayoutParams(MATCH_PARENT, height, TYPE_SYSTEM_ERROR,
FLAG_NOT_FOCUSABLE
| FLAG_LAYOUT_IN_SCREEN
| FLAG_LAYOUT_NO_LIMITS
| FLAG_NOT_TOUCH_MODAL
| FLAG_LAYOUT_INSET_DECOR
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
, TRANSLUCENT);
params.gravity = Gravity.TOP;
return params;
}
public int retrieveScreenHeight() {
int result = 0;
WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE);
Point outSize = new Point();
wm.getDefaultDisplay().getSize(outSize);
if(outSize.y > outSize.x){
result = outSize.y;
}else{
result = outSize.x;
}
return result;
}
I assume you'll want to make the activity that hosts the overlay view as fullscreen if you want to cover the system bar.
Something like below code.
public class ActivityName extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
Then your activity will not show the system bar, and you'll have your view going all the way to the top of the screen.
EDIT : From your last comment, here's how I'd do it :
Step 1 : Create this FullScreenLockActivity :
public class FullScreenLockActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
// set to fullScreen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//Load your black semi-transparent view
setContentView(R.layout.lock_screen);
}
//Override this to prevent the user to close this activity by pressing the back button
#Override
public void onBackPressed() {}
}
Step 2 : Implement your "unlock screen" behavior in the FullScreenLockActivity
Step 3 : To display the lock screen, call
Intent i = new Intent(yourCurrentActivity.this, FullScreenLockActivity.class);
startActivity(i);

In which state activity measure it's view

I have created a custom ViewGroup ReadPage, and in activity I use it
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
pager=(ReadPage)findViewById(R.id.readpage);
pager.addArticle("...");
}
While the addArticle need the view's width and height
public void addArticle(String s){
articles.add(new Article(s,getMeasuredWidth(),getMeasuredHeight()));
}
But the measurewidth and measureheight is 0 at that time.
So I want to know at which state the view will be measured so I can get the right value it show in screen.
This answer probably gives you what you need: https://stackoverflow.com/a/1016941/213528
You would maybe use it like this:
private int WIDTH;
private int HEIGHT;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
WIDTH = size.x;
HEIGHT = size.y;
pager = (ReadPage)findViewById(R.id.readpage);
pager.addArticle("...");
}
// ...
public void addArticle(String s){
articles.add(new Article(s, WIDTH, HEIGHT));
}
Use ViewTreeObserver
viewToMeasure.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
viewToMeasure.getViewTreeObserver().removeGlobalOnLayoutListener(this);
/* you can get the view's height and width here
using viewToMeasure.getWidth() and viewToMeasure.getHeight()
*/
}
});
Views are measured sometimes later, during a "measure pass". When View structure changes (due to adding , removing, updating a view), a measure and then a layout pass runs that re-calculates the View sizes and locations.
For example, you can set text data to a TextView any time, but the View itself decides how to display it, when it is ready to display it. The text warp etc is calculated then, and not while setting the text.
You should design the View displaying the Article to be similar. You can provide the data, but let View process and display it further when its onSizeChanged() is called. Views can also employ addOnLayoutChangeListener() to know when layout has been done.

Displaying the captured image in full screen

In my application, I have to show the captured image from camera in full screen like in Snapshot. I could make the camera preview (surface view) to display in full screen. But when I display the captured image in ImageView, it is not displaying in the full screen.
Any help will be much appreciated.
1- If you want your Activity be full screen,do some thing like this:
public class ActivityName extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// remove title
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.main);
}
}
(more details here)
2- If you want your ImageView be full screen,create instance of ImageView then set it as ContentView of your Activity or create a layout that image view completely covers that and set that layout as ContentView.
I set the scale type property of Image view as 'centerCrop' (android:scaleType="centerCrop"). Now its working fine.

Getting shadows/outlines/shapes of icons

I was wondering if it is possible to get shadows/shapes of icons on home screen in android? I know when you add some custom icon to your homescreen and then move it around you get outlines of that icon. ( at least in samsungs TouchWiz 4+ and API 11+ ). So is there a way to obtain shapes and locations of icons on homescreen?
Here is a short sample of what you could do:
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageView view = ((ImageView) findViewById(R.id.img_outline));
view.setImageBitmap(createOutline(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)));
view.setColorFilter(Color.RED);
}
private Bitmap createOutline(Bitmap src) {
Paint p = new Paint();
p.setMaskFilter(new BlurMaskFilter(10, Blur.OUTER));
return src.extractAlpha(p, null);
}
}
Is that what you had in mind? (Note that if you have to align the blurred image with the original you should pass an int array of length two to extractAlpha. The array will contain the offsets you should use to align the outline.)

Categories

Resources