Posts

Showing posts from February, 2017

Implement transparent status bar for android.support.v7.widget.Toolbar

Image
Implement transparent status bar for android.support.v7.widget.Toolbar: - Follow the steps in " Replace ActionBar with android.support.v7.widget.Toolbar " to implement a simplest toolbar. - Edit styles.xml to add the item of "android:windowTranslucentStatus". Edit MainActivity.java to set the padding (with the height of status bar ) of the status. package com.blogspot.android_er.androidtoolbarex2; import android.content.res.Resources; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar); setSupportActionBar(toolbar); toolbar.setPadding(0, getStatusBarHeight(), 0, 0); }

Get the height of status bar

Image
Example to get the height of status bar, in size of pixel. package com.blogspot.android_er.androidgetstatusbarheight; import android.content.res.Resources; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getStatusBarHeight(); } private int getStatusBarHeight() { int height; Resources myResources = getResources(); int idStatusBarHeight = myResources.getIdentifier( "status_bar_height", "dimen", "android"); if (idStatusBarHeight > 0) { height = getResources().getDimensionPixelSize(idStatusBarHeight); Toast.makeText(this, "Status Bar Height = " + height,

Remix OS is Android PC. Re-imagining mobile. Redefining PC.

Image
Remix OS for PC , now powered by Android Marshmallow,  allows you to run PC optimized version of Android on any computer. Through a simple and quick setup process, enjoy millions of Android apps and games on your PC alongside the many intuitive and amazing PC features we’ve engineered into Remix OS. Learn more:  http://www.jide.com/remixos-for-pc

Building interfaces with ConstraintLayout in Android Studio

Image
The new Layout Editor in Android Studio 2.2 include a new blueprint mode, revamped properties inspector and support for ConstraintLayout , a new way to define layouts for your apps. In this Android Tool Time episode Wojtek Kaliciński shows you the basics of working with ConstraintLayouts in the visual editor. If you want to try it out yourself, you can find our codelab here: https://codelabs.developers.google.com/codelabs/constraint-layout When you’re familiar with the layout editor interface, read the rest of our Medium article where you’ll find some more advanced tips and tricks for ConstraintLayout: https://goo.gl/a5orYw

IOException: not create document. Error

Image
When I prepare the example " Display PDF in assets folder (inside APK) ", I face with the error of "java.io.IOException: not create document. Error". It should be generated by the code: pdfRenderer = new PdfRenderer(fileDescriptor); Somebody commented it's caused by new version of Gradle (ref: https://github.com/googlesamples/android-PdfRendererBasic/issues/1 ), so I edit dependencies of buildscript in build.gradle (Project: ...), use gradle:2.1.2 to solve this problem.

Display PDF in assets folder (inside APK)

Image
The example " Display PDF using PdfRenderer " show how to display PDF stored in sdcard, this example show how to display PDF stored in assets inside APK. First, you have to create assets folder and copy your PDF into it. Then you have to edit aaptOptions in build.gradle (Module: app), not to compass "pdf" file. aaptOptions { noCompress "pdf" } Layout file, refer to the example " Create PDF using PdfDocument ". MainActivity.java package com.blogspot.android_er.androidpdf; import android.content.res.AssetFileDescriptor; import android.content.res.AssetManager; import android.graphics.Bitmap; import android.graphics.pdf.PdfRenderer; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.support.v7.app.AppCompatActivity; import android.widget.ImageView; import android.widget.Toast; import java.io.IOException; public class MainActivity extends AppCompatActivity { ImageView pdfView; @Override protec

Create assets folder in Android Studio, and copy file into.

Image
How to create assets folder in Android Studio, and copy a PDF file into the assets folder.

Create PDF using PdfDocument

Image
android.graphics.pdf.PdfDocument enables generating a PDF document from native Android content. This example show how to create a two page PDF file using PdfDocument, store as "/sdcard/test.pdf". Then use last example  Display PDF using PdfRenderer to view it. (remark: if you use last example to view the PDF file, you have to change targetPdf = "/sdcard/test.pdf".) MainActivity.java package com.blogspot.android_er.androidcreatepdf; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.pdf.PdfDocument; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.Toast; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; public class MainActivity extends AppCompatActivity { Button btnCreate; @Override protected void onCreate(Bundle savedInstanceState) { super.onCr

Display PDF using PdfRenderer

Image
The class android.graphics.pdf.PdfRenderer enables rendering a PDF document. This example show how to: MainActivity.java package com.blogspot.android_er.androidpdf; import android.graphics.Bitmap; import android.graphics.pdf.PdfRenderer; import android.os.Bundle; import android.os.ParcelFileDescriptor; import android.support.v7.app.AppCompatActivity; import android.widget.ImageView; import android.widget.Toast; import java.io.File; import java.io.IOException; public class MainActivity extends AppCompatActivity { String targetPdf = "/sdcard/MagPi54.pdf"; ImageView pdfView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); pdfView = (ImageView)findViewById(R.id.pdfview); try { openPDF(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(this, "Something Wrong: &q

Change minSdkVersion, targetSdkVersion, compileSdkVersion in Android Studio

Image
To change minSdkVersion in Android Studio: - Right click your app -> Open Module Settings - Select app and Flavors tab, select your new Min Sdk Version, then OK. - minSdkVersion changed. You can also change targetSdkVersion, compileSdkVersion (under Properties tab) also.

First try ConstraintLayout

Image
ConstraintLayout allows you to create large and complex layouts with a flat view hierarchy (no nested view groups). It's similar to RelativeLayout in that all views are layed out according to relationships between sibling views and the parent layout, but it's more flexible than RelativeLayout and easier to use with Android Studio's Layout Editor. To use ConstraintLayout, make sure to install Support Repository of ConstraintLayout for Android and Solver for ConstraintLayout in Android SDK Manager: Add dependency of ConstraintLayout library in your module-level build.gradle file: dependencies { compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4' } In the toolbar or sync notification, click Sync Project with Gradle Files. We can convert an existing layout to a constraint layout in Android Studio's Layout Editor: - Open your layout in Android Studio and click the Design tab at the bottom of the editor window. - In the Component Tree window, r