關於條碼掃描Zxing,需要掃描時直立顯示:
android提供的SDK(android.hardware.Camera)裡大概不能正常的使用直立顯示(portrait layout)加載照相機,當用直立顯示模式加載照相機時會產生以下情況:
1.照相機成像左傾90度(傾斜);
2.照相機成像長寬比例不對(失比)。
基本上解決辦法如下:
1、在AndroidManifest.xml裡面配置一下 ,使CaptureActivity属性為portrait:android:screenOrientation="portrait"
2、如果只是單純的想改變照相機成像的方向,只需要在com.google.zxing.client.android.camera下的 CameraConfigurationManager類別中增加方法
protected void setDisplayOrientation(Camera camera, int angle) {
Method downPolymorphic;
try {
downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] { int.class });
if (downPolymorphic != null)
downPolymorphic.invoke(camera, new Object[] { angle });
} catch (Exception e1) { }
}
然後在方法void setDesiredCameraParameters(Camera camera){}中調用, setDisplayOrientation(camera, 90); 具體位置在camera.setParameters(parameters);語句前面。
3、改變完方向你會發現方向改變可可分辨率會變得很低,接下來就是優化了
1)首先在類別CameraManager.java中把
rect.left = rect.left * cameraResolution.x / screenResolution.x;
rect.right = rect.right * cameraResolution.x / screenResolution.x;
rect.top = rect.top * cameraResolution.y / screenResolution.y;
rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;
替換成
rect.left = rect.left * cameraResolution.y / screenResolution.x;
rect.right = rect.right * cameraResolution.y / screenResolution.x;
rect.top = rect.top * cameraResolution.x / screenResolution.y;
rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;
(2)然後是在DecodeHandler類別中的方法private void decode(byte[] data,int width,int height){}中添加
byte[] rotatedData = new byte[data.length];
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++)
rotatedData[x * height + height - y - 1] = data[x + y * width];
(3)再就是CameraConfigurationManager類別中的方法void initFromCameraParameters(Camera camera){}中添加如下代碼:
Point screenResolutionForCamera = new Point();
screenResolutionForCamera.x = screenResolution.x;
screenResolutionForCamera.y = screenResolution.y;
// preview size is always something like 480*320, other 320*480
if (screenResolution.x < screenResolution.y) {
screenResolutionForCamera.x = screenResolution.y;
screenResolutionForCamera.y = screenResolution.x;
2016年12月19日
2016年12月10日
JackyAndJustin Android App 隱私權政策
JackyAndJustin Android App Privacy Policy
Information that may be collected from you
When you use this app, you do not need to enter your personal information (such as your name, ID number, email address, etc.). You will not acquire your personal information without your knowledge, unless you know in advance.
Third-party website
This service may include links to third party services or other third party websites that include the retailer with whom you deal. Please note that this policy applies only to personal information we collect through our services and we are not responsible for the personal information that third parties may collect, store and use through their websites or services. You should always read through the privacy policies of every web site you visit.
This policy change
We may from time to time make changes to this policy for a variety of reasons, for example, to reflect changes in laws and regulations or changes in industry specifications and technology.
If you have any questions or comments about this policy, please contact us.
隱私權政策
可能向您收集之資訊
您使用此APP時,並不需要輸入個人資料 (例如姓名、身分證字號、電子郵件地址等 ) ,除非事先告知,此APP不會在您不知情的狀況下,取得您個人資料。
第三方網站
本服務可能包含連至第三方服務或第三方其他網站之連結,這個第三方包括與您進行交易的零售商。請注意,本政策僅適用於我方透過服務收集的個人資訊,我方不對第三方可能透過其網站或服務收集、存儲及使用的個人資訊負有責任。您應始終仔細閱讀每個您瀏覽網站的隱私權政策。
本政策的變更
我方可能因各種原因而需不時對本政策進行變更,例如,為了反應法律與法規的變更或行業規範與技術發展的改變。
如果您對本政策有任何問題或意見,請聯絡我們。
Information that may be collected from you
When you use this app, you do not need to enter your personal information (such as your name, ID number, email address, etc.). You will not acquire your personal information without your knowledge, unless you know in advance.
Third-party website
This service may include links to third party services or other third party websites that include the retailer with whom you deal. Please note that this policy applies only to personal information we collect through our services and we are not responsible for the personal information that third parties may collect, store and use through their websites or services. You should always read through the privacy policies of every web site you visit.
This policy change
We may from time to time make changes to this policy for a variety of reasons, for example, to reflect changes in laws and regulations or changes in industry specifications and technology.
If you have any questions or comments about this policy, please contact us.
隱私權政策
可能向您收集之資訊
您使用此APP時,並不需要輸入個人資料 (例如姓名、身分證字號、電子郵件地址等 ) ,除非事先告知,此APP不會在您不知情的狀況下,取得您個人資料。
第三方網站
本服務可能包含連至第三方服務或第三方其他網站之連結,這個第三方包括與您進行交易的零售商。請注意,本政策僅適用於我方透過服務收集的個人資訊,我方不對第三方可能透過其網站或服務收集、存儲及使用的個人資訊負有責任。您應始終仔細閱讀每個您瀏覽網站的隱私權政策。
本政策的變更
我方可能因各種原因而需不時對本政策進行變更,例如,為了反應法律與法規的變更或行業規範與技術發展的改變。
如果您對本政策有任何問題或意見,請聯絡我們。
2016年12月8日
Android 使用Snackbar跟CoordinatorLayout
Android 使用Snackbar跟CoordinatorLayout
build.gradle
dependencies {
compile 'com.android.support:design:24.2.1'
}
activity_main.xml布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:onClick="createSnackbar"
android:text="@string/snackbar_test_button_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
MainActivity
container = (CoordinatorLayout) findViewById(R.id.container);
Snackbar.make(container, "This is explanation: Please give us permission", Snackbar.LENGTH_LONG)
.setAction("OK", new View.OnClickListener() {
@Override
public void onClick(View view) {
requestExternalStoragePermission();
}
}).show();
build.gradle
dependencies {
compile 'com.android.support:design:24.2.1'
}
activity_main.xml布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:onClick="createSnackbar"
android:text="@string/snackbar_test_button_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
MainActivity
container = (CoordinatorLayout) findViewById(R.id.container);
Snackbar.make(container, "This is explanation: Please give us permission", Snackbar.LENGTH_LONG)
.setAction("OK", new View.OnClickListener() {
@Override
public void onClick(View view) {
requestExternalStoragePermission();
}
}).show();
2016年11月25日
Android 禁止螢幕旋轉
Android 禁止螢幕旋轉
AndroidManifest.xml設置
android:screenOrientation="portrait" (強制直向)
android:screenOrientation="landscape" (強制橫向)
Java Code設置
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//畫面直向
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//畫面橫向
以上畫面只要轉方向時,activity 會重新執行。
1、如果不要 activity 重新執行,需要在 AndroidManifest.xml 檔案中,在 activity 加入 android:configChanges="orientation|keyboardHidden" 就會禁止重新執行。
這個屬性指的是,當後邊屬性值代表的事件發生時,Activity 會執行某個函數,orientation 指的是當螢幕旋轉時,keyboardHidden 指的是鍵盤輔助功能改變。“|”為或符號,指這兩個中任意一個發生,就執行 Activity 某個函數。
如果你的開發 API 等級等於或高於 13,你還需要設置 screenSize,因為 screenSize 會在螢幕旋轉時改變。
2、在對應 Activity 中重寫 onConfigurationChanged() 方法:
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
// 什麼都不用寫
}
else {
// 什麼都不用寫
}
}
如果在 if、else 中,使用了 setContentView(R.layout.xxxx) 函數,那麼就可以實現:每次螢幕旋轉時,調用不同的佈局。
3、動態更改螢幕方向:
在程式中有需要的時候旋轉螢幕,例如
@Override
public void onClick(View v) {
// 如果是豎排,則改為橫向
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
// 如果是橫排,則改為直向
else if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
重點就是:getRequestedOrientation() 函數、setRequestedOrientation() 函數的使用。
注意:使用這種方法,必須事先在 AndroidManifest.xml 的 <activity> </activity> 中,添加android:screenOrientation 屬性值,不然 getRequestedOrientation() 可能會出問題。
AndroidManifest.xml設置
android:screenOrientation="portrait" (強制直向)
android:screenOrientation="landscape" (強制橫向)
Java Code設置
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//畫面直向
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//畫面橫向
以上畫面只要轉方向時,activity 會重新執行。
1、如果不要 activity 重新執行,需要在 AndroidManifest.xml 檔案中,在 activity 加入 android:configChanges="orientation|keyboardHidden" 就會禁止重新執行。
這個屬性指的是,當後邊屬性值代表的事件發生時,Activity 會執行某個函數,orientation 指的是當螢幕旋轉時,keyboardHidden 指的是鍵盤輔助功能改變。“|”為或符號,指這兩個中任意一個發生,就執行 Activity 某個函數。
如果你的開發 API 等級等於或高於 13,你還需要設置 screenSize,因為 screenSize 會在螢幕旋轉時改變。
2、在對應 Activity 中重寫 onConfigurationChanged() 方法:
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
// 什麼都不用寫
}
else {
// 什麼都不用寫
}
}
如果在 if、else 中,使用了 setContentView(R.layout.xxxx) 函數,那麼就可以實現:每次螢幕旋轉時,調用不同的佈局。
3、動態更改螢幕方向:
在程式中有需要的時候旋轉螢幕,例如
@Override
public void onClick(View v) {
// 如果是豎排,則改為橫向
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
// 如果是橫排,則改為直向
else if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
}
重點就是:getRequestedOrientation() 函數、setRequestedOrientation() 函數的使用。
注意:使用這種方法,必須事先在 AndroidManifest.xml 的 <activity> </activity> 中,添加android:screenOrientation 屬性值,不然 getRequestedOrientation() 可能會出問題。
2016年11月23日
Android Intent用法
Android Intent用法
顯示網頁
Uri uri = Uri.parse("http://google.com");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
使用郵件MAIL
//傳送文字
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress@emailaddress.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");
startActivity(Intent.createChooser(intent, "Send Email"));
//傳送影音附件檔
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/mysong.mp3"));
it.setType("audio/mp3");
startActivity(Intent.createChooser(it, "Choose Email Client"));
//傳送圖片附件檔
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/mypic.jpg"));
it.setType("image/jpeg");
startActivity(Intent.createChooser(it, "Choose Email Client"));
撥打電話
//叫出撥號程式
Uri uri = Uri.parse("tel:0800000123");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);
//直接打電話出去
Uri uri = Uri.parse("tel:0800000123");
Intent it = new Intent(Intent.ACTION_CALL, uri);
startActivity(it);
//用這個,要在 AndroidManifest.xml 中,加上
//<uses-permission id="android.permission.CALL_PHONE" />
顯示聯絡人清單
Intent it = new Intent(Intent.ACTION_VIEW, People.CONTENT_URI);
startActivity(it);
播放多媒體
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
安裝 APK 檔
Uri uri = Uri.parse("url_of_apk_file");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
it.setData(uri);
it.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
it.setClassName("com.android.packageinstaller",
"com.android.packageinstaller.PackageInstallerActivity");
startActivity(it);
//make sure the url_of_apk_file is readable for all users
顯示網頁
Uri uri = Uri.parse("http://google.com");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
使用郵件MAIL
//傳送文字
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL, "emailaddress@emailaddress.com");
intent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intent.putExtra(Intent.EXTRA_TEXT, "I'm email body.");
startActivity(Intent.createChooser(intent, "Send Email"));
//傳送影音附件檔
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/mysong.mp3"));
it.setType("audio/mp3");
startActivity(Intent.createChooser(it, "Choose Email Client"));
//傳送圖片附件檔
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_SUBJECT, "The email subject text");
it.putExtra(Intent.EXTRA_STREAM, Uri.parse("file:///sdcard/mypic.jpg"));
it.setType("image/jpeg");
startActivity(Intent.createChooser(it, "Choose Email Client"));
撥打電話
//叫出撥號程式
Uri uri = Uri.parse("tel:0800000123");
Intent it = new Intent(Intent.ACTION_DIAL, uri);
startActivity(it);
//直接打電話出去
Uri uri = Uri.parse("tel:0800000123");
Intent it = new Intent(Intent.ACTION_CALL, uri);
startActivity(it);
//用這個,要在 AndroidManifest.xml 中,加上
//<uses-permission id="android.permission.CALL_PHONE" />
顯示聯絡人清單
Intent it = new Intent(Intent.ACTION_VIEW, People.CONTENT_URI);
startActivity(it);
播放多媒體
Intent it = new Intent(Intent.ACTION_VIEW);
Uri uri = Uri.parse("file:///sdcard/song.mp3");
it.setDataAndType(uri, "audio/mp3");
startActivity(it);
Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
startActivity(it);
安裝 APK 檔
Uri uri = Uri.parse("url_of_apk_file");
Intent it = new Intent(Intent.ACTION_VIEW, uri);
it.setData(uri);
it.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
it.setClassName("com.android.packageinstaller",
"com.android.packageinstaller.PackageInstallerActivity");
startActivity(it);
//make sure the url_of_apk_file is readable for all users
2016年11月19日
Android 常用系統預設文字大小以及顏色
Android 常用系統預設文字大小以及顏色
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
android:textAppearance="?android:attr/textAppearanceLarge" 或是
sytle="?android:attr/textAppearanceLarge" 實際上是一樣的。
文字大小
android:textAppearance="?android:attr/textAppearanceLarge"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textAppearance="?android:attr/textAppearanceSmall"
字體顏色
android:textColor="?android:attr/textColorPrimary"
android:textColor="?android:attr/textColorSecondary"
android:textColor="?android:attr/textColorTertiary"
android:textColor="?android:attr/textColorPrimaryInverse"
android:textColor="?android:attr/textColorSecondaryInverse"
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
android:textAppearance="?android:attr/textAppearanceLarge" 或是
sytle="?android:attr/textAppearanceLarge" 實際上是一樣的。
文字大小
android:textAppearance="?android:attr/textAppearanceLarge"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textAppearance="?android:attr/textAppearanceSmall"
字體顏色
android:textColor="?android:attr/textColorPrimary"
android:textColor="?android:attr/textColorSecondary"
android:textColor="?android:attr/textColorTertiary"
android:textColor="?android:attr/textColorPrimaryInverse"
android:textColor="?android:attr/textColorSecondaryInverse"
2016年11月14日
Android studio測試問題 測試會出現安裝兩個相同APP
Android studio測試問題 測試會出現安裝兩個相同APP
問題出現在AndroidManifest.xml寫入2個Activity<intent-filter>
只要刪除底下紅色字體代碼即可以修正錯誤,正常測試。
AndroidManifest.xml
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SetupActivityListSample"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
2016年11月7日
Android AlertDialog
Android AlertDialog
建立AlertDialog對話盒
AlertDialog.Builder builder = new AlertDialog.Builder(gameViewA.getContext());
builder.setTitle("抬頭訊息...");
builder.setMessage("本文訊息");
builder.setNegativeButton("右邊按鈕", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
builder.setNeutralButton("中間按鈕", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
builder.setPositiveButton("左邊按鈕", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
建立AlertDialog對話盒
AlertDialog.Builder builder = new AlertDialog.Builder(gameViewA.getContext());
builder.setTitle("抬頭訊息...");
builder.setMessage("本文訊息");
builder.setNegativeButton("右邊按鈕", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
builder.setNeutralButton("中間按鈕", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
builder.setPositiveButton("左邊按鈕", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
2016年11月6日
Android SensorManager Accuracy Value
Android SensorManager Accuracy Value
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
int accuracy
int SENSOR_STATUS_ACCURACY_HIGH
This sensor is reporting data with maximum accuracy
Constant Value: 3 (0x00000003)
int SENSOR_STATUS_ACCURACY_LOW
This sensor is reporting data with low accuracy, calibration with the environment is needed
Constant Value: 1 (0x00000001)
int SENSOR_STATUS_ACCURACY_MEDIUM
This sensor is reporting data with an average level of accuracy, calibration with the environment may improve the readings
Constant Value: 2 (0x00000002)
int SENSOR_STATUS_NO_CONTACT
The values returned by this sensor cannot be trusted because the sensor had no contact with what it was measuring (for example, the heart rate monitor is not in contact with the user).
Constant Value: -1 (0xffffffff)
int SENSOR_STATUS_UNRELIABLE
The values returned by this sensor cannot be trusted, calibration is needed or the environment doesn't allow readings
Constant Value: 0 (0x00000000)
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
int accuracy
int SENSOR_STATUS_ACCURACY_HIGH
This sensor is reporting data with maximum accuracy
Constant Value: 3 (0x00000003)
int SENSOR_STATUS_ACCURACY_LOW
This sensor is reporting data with low accuracy, calibration with the environment is needed
Constant Value: 1 (0x00000001)
int SENSOR_STATUS_ACCURACY_MEDIUM
This sensor is reporting data with an average level of accuracy, calibration with the environment may improve the readings
Constant Value: 2 (0x00000002)
int SENSOR_STATUS_NO_CONTACT
The values returned by this sensor cannot be trusted because the sensor had no contact with what it was measuring (for example, the heart rate monitor is not in contact with the user).
Constant Value: -1 (0xffffffff)
int SENSOR_STATUS_UNRELIABLE
The values returned by this sensor cannot be trusted, calibration is needed or the environment doesn't allow readings
Constant Value: 0 (0x00000000)
2016年10月27日
Android view setVisibility():
Android view setVisibility():
有三個參數:Parameters: visibility One of VISIBLE , INVISIBLE , GONE,
對應的常量值:0、4、8
VISIBLE:0 意思是可見的
INVISIBILITY:4 意思是不可見的,但還佔著原來的空間
GONE:8 意思是不可見的,不佔用原來的佈局空間
View Code
LinearLayout num_Layout = (LinearLayout) findViewById(R.id.num_layout);
if (numberOfRecord > 0){
TextView num = (TextView) findViewById(R.id.num);
num.setText(numberOfRecord.toString() );
num_Layout.setVisibility(0);
}
else {
num_Layout.setVisibility(8);
}
有三個參數:Parameters: visibility One of VISIBLE , INVISIBLE , GONE,
對應的常量值:0、4、8
VISIBLE:0 意思是可見的
INVISIBILITY:4 意思是不可見的,但還佔著原來的空間
GONE:8 意思是不可見的,不佔用原來的佈局空間
View Code
LinearLayout num_Layout = (LinearLayout) findViewById(R.id.num_layout);
if (numberOfRecord > 0){
TextView num = (TextView) findViewById(R.id.num);
num.setText(numberOfRecord.toString() );
num_Layout.setVisibility(0);
}
else {
num_Layout.setVisibility(8);
}
2016年10月4日
Android Studio You can also reset/revoke a specific permissions using
Android Studio
You can also reset/revoke a specific permissions using
adb shell pm grant com.your.flashlight android.permission.CAMERA
adb shell pm revoke com.your.package android.permission.CAMERA
adb shell pm grant android.permission.CAMERA
adb shell pm reset-permissions
you should also add C:/android-sdk/platform-tools to you environment path
2016年8月21日
Flashlight App For Android
Flashlight App For Android
Google play>Flashlight App
Original design. A brand-new easy-to-use interface. Fast, bright, colorful, beautiful and featuring instant-on startup.
It has the standard lowest-permissions-needed and the standard ability to turn on your LED flash on the back of your phone.
LED flash
Interface color changes
Countdown
SOS flash
Thanks for all your feedback and support!
Google play>Flashlight App
Original design. A brand-new easy-to-use interface. Fast, bright, colorful, beautiful and featuring instant-on startup.
It has the standard lowest-permissions-needed and the standard ability to turn on your LED flash on the back of your phone.
LED flash
Interface color changes
Countdown
SOS flash
Thanks for all your feedback and support!
2016年6月13日
Draw SurfaceView from layout xml
Draw SurfaceView from layout xml
Xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="@+id/textView_idd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<jacky.justin.superflashlight.GameViewA
android:id="@+id/surfaceView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</RelativeLayout>
MySurfaceView
public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback, OnTouchListener {
MainActivity mainActivity;
public GameViewA(Context context) {
super(context);
}
public GameViewA(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public GameViewA(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
}
Xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="@+id/textView_idd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<jacky.justin.superflashlight.GameViewA
android:id="@+id/surfaceView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</FrameLayout>
</RelativeLayout>
MySurfaceView
public class MySurfaceView extends SurfaceView implements SurfaceHolder.Callback, OnTouchListener {
MainActivity mainActivity;
public GameViewA(Context context) {
super(context);
}
public GameViewA(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
public GameViewA(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}
}
2016年3月19日
Android Studio API Level Change
Android Studio API Level Change
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.justin.jacky.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.justin.jacky.myapplication"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
訂閱:
文章 (Atom)