Monthly Archives: 12月 2014

「android開発」画面の幅と高さを取得する方法

1.Javaコード:
int height = getWindowManager().getDefaultDisplay().getHeight();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
2.AndroidManifest.xmlに下記を追加
<supports-screens
android:smallScreens=”true”
android:normalScreens=”true”
android:largeScreens=”true”
android:resizeable=”true”
android:anyDensity=”true” />

「Android開発」画面サイズを自動的に調整する

Javaコード:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button bt;
Button bt2;
Button bt3; Button bt4;
bt=(Button)findViewById(R.id.button1);
bt2=(Button)findViewById(R.id.button2);
bt3=(Button)findViewById(R.id.button3);
bt4=(Button)findViewById(R.id.button4);
Display display = this.getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height=display.getHeight();
bt.setHeight((int) ((height)*0.2));
bt2.setHeight((int) ((height)*0.3));
bt3.setHeight((int) ((height)*0.3));
bt4.setHeight((int) ((height)*0.2));

}

「android開発」パッケージ名を変更する手順

手順
1.srcのパッケージ部分を右クリックして、refactor->renameで変更
例org.monsterlab.startnews24demo

2.AndroidManifest.xmlのパッケージ名を変更
package=”com.example.startnews24demo”

3.パッケージエクスプローラでのgen以下の旧パッケージを削除

「Objective-C」ios開発でデバイス名と解像度を取得するサンプルコード

ダウンロード
https://github.com/InderKumarRathore/UIDeviceUtil
https://github.com/SVGKit/SVGKit

サンプルコード:
size_t size;
sysctlbyname(“hw.machine”, NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname(“hw.machine”, machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);

if( [platform hasPrefix:@”iPhone1″]
|| [platform hasPrefix:@”iPhone2″]
|| [platform hasPrefix:@”iPhone3″])
return 163.0f;

if( [platform hasPrefix:@”iPhone4″]
|| [platform hasPrefix:@”iPhone5″]
|| [platform hasPrefix:@”iPhone6″])
return 326.0f;

//
//
// Note: iPhone6 326ppi
if( [platform hasPrefix:@”iPhone7″]) {
return 401.0f;
}

if( [platform hasPrefix:@”iPhone”]) // catch-all for higher-end devices not yet existing
{
NSAssert(FALSE, @”Not supported yet: you are using an iPhone that didn’t exist when this code was written, we have no idea what the pixel count per inch is!”);
return 326.0f;
}

if( [platform hasPrefix:@”iPod1″]
|| [platform hasPrefix:@”iPod2″]
|| [platform hasPrefix:@”iPod3″])
return 163.0f;

if( [platform hasPrefix:@”iPod4″]
|| [platform hasPrefix:@”iPod5″])
return 326.0f;

if( [platform hasPrefix:@”iPod”]) //ハイエンドデバイス
{
NSAssert(FALSE, @”Not supported yet: you are using an iPod that didn’t exist when this code was written, we have no idea what the pixel count per inch is!”);
return 326.0f;
}

if( [platform hasPrefix:@”iPad1″]
|| [platform hasPrefix:@”iPad2″])
return 132.0f;
if( [platform hasPrefix:@”iPad3″]
|| [platform hasPrefix:@”iPad4″])
return 264.0f;
if( [platform hasPrefix:@”iPad”]) // catch-all for higher-end devices not yet existing
{
NSAssert(FALSE, @”Not supported yet: you are using an iPad that didn’t exist when this code was written, we have no idea what the pixel count per inch is!”);
return 264.0f;
}

if( [platform hasPrefix:@”x86_64″])
{
DDLogWarn(@”[%@] WARNING: you are running on the simulator; it’s impossible for us to calculate centimeter/millimeter/inches units correctly”, [self class]);
return 132.0f; // シミュレータ、デスクトップマシンで実行

ドライバを削除するソフトTreexy Driver Fusion 2.7.0.0 ダウンロード

ダウンロード
開発元サイトからダウンロード
Softpediaサイトからダウンロード
cnetサイトからダウンロード

更新内容
新機能:
[Premium] Health check – Community suggested feature – Added a progress indicator to visualize the device that is currently being fixed.
変更点:
[Premium] Health check – Improved the ordering of missing and outdated drivers.
Desktop – Improved the performance of restoring the desktop icons.
Settings – The settings are now automatically saved after every change instead of only on close.
Service – The online service that allows you to gain access to several features, such as the automatic driver updated, has been completely rewritten. This new online service enables us to deploy new versions more easily without disrupting the service and is also more friendly to firewalls. The old online service will remain fully functional until February 1st, 2015. After this date only signing in with your email address and updating will remain functional for the old online service. As of Driver Fusion 2.7 the new online service will be used.
不具合の修復:
[Premium] Device control – Identify could in some cases not show any results.
[Premium] Device control – Reselecting a device could occasionally cause Driver Fusion to freeze or close unintentionally.
[Premium] Device control – The backed up driver text did not update after selecting another destination.
[Premium] Device control – Changing the sort order of online drivers could in some cases cause Driver Fusion to freeze or close unintentionally.
Desktop – Desktop icons could in some cases not restore to the correct location.

Uninxでgradle-2.2.1をインストール、コンパイルする方法

1.gradle-2.2.1のダウンロード
http://www.gradle.org/downloads

2.解凍

2.1 cd gradle-2.2.1 cd ..

2.2 ターミナル:sudo su pwd*****

2.3 mv gradle-2.2.1 /usr/local/bin/gradle-2.2.1

2.4 vim .bash_profile

2.5 コピー
GRADLE_HOME=/usr/local/bin/gradle-2.2.1;
export GRADLE_HOME
export PATH=$PATH:$GRADLE_HOME/bin

2.6 esc,:wq で終了

2.7 gradle -versionでバージョンを確認

コマンド:
gradle build

「android開発」クライアントのバーコードボックスを処理

参考コード:
private static int findDesiredDimensionInRange(int resolution, int hardMin, int hardMax) {
int dim = 5 * resolution / 8; // Target 5/8 of each dimension
if (dim < hardMin) { return hardMin; } if (dim > hardMax) {
return hardMax;
}
return dim;
}

「android開発」Activityから別のActivityを起動させるデータ(IntentとBundle)を渡す方法

方法1
intent = new Intent(MainActivity.this,Second.class);
bundle = new Bundle();
bundle.putString(“startnews24”, ed_content.getText().toString());
intent.putExtras(bundle);
startActivity(intent);
//受信処理
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
tv_show.setText(bundle.getString(“startnews24”));

方法2
intent = new Intent();
intent.setClass(MainActivity.this,Second.class);
intent.putExtra(“key”, “dash”);
startActivity(intent);
//受信処理
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String name = bundle.getString(“key”);
tv_show.setText(name);

「android開発」ThreadとHandlerでマルチスレッド処理するサンプルコード

サンプルコード:
package com.startnews24.handler;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

private Button btn_show;
private TextView tv_show;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

btn_show = (Button)findViewById(R.id.btn_show);
tv_show = (TextView)findViewById(R.id.tv_show);

btn_show.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
thread.start();
}
});
System.out.println(“親スレッド:” + Thread.currentThread().getName());
}

private Handler handler = new Handler(){

@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
if(msg.what == 5){
tv_show.setText(“子スレッドのメッセージを取得”);
}
}
};

private Thread thread = new Thread(){

@Override
public void run() {
super.run();
try {
thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Message msg = handler.obtainMessage();
msg.what = 5;
System.out.println(“子スレッド:”+
thread.currentThread().getName());
handler.sendMessage(msg);
}
};

@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;
}

}

「android開発」postでクライアントログイン機能を実現するサンプルコード

サンプルコード:
public class MainActivity extends Activity {
private EditText ed_name;
private EditText ed_startnews24passowrd;
private Button btn_login;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed_name = (EditText)findViewById(R.id.username);
ed_startnews24passowrd = (EditText)findViewById(R.id.ustartnews24passowrd);
btn_login = (Button)findViewById(R.id.btn_login);
btn_login.setOnClickListener(new MyButtonListener());
}

class MyButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
String name = ed_name.getText().toString();
String startnews24passowrd = ed_startnews24passowrd.getText().toString();
PostThread pt = new PostThread(name, startnews24passowrd);
pt.start();

}

}
/
*ログイン成功するかどうかを判断
*/

//postでデータを送信
class PostThread extends Thread{
String name;
String startnews24passowrd;
public PostThread(String name, String startnews24passowrd) {
super();
this.name = name;
this.startnews24passowrd = startnews24passowrd;
}
@Override
public void run() {
super.run();
HttpClient httpClient = new DefaultHttpClient();
String url = “http://192.168.200.1:8080/2.5/LoginServlet”;
HttpPost httpPost = new HttpPost(url);

//NameValuePairオブジェクト
NameValuePair pair1 = new BasicNameValuePair(“username”, name);
NameValuePair pair2 = new BasicNameValuePair(“ustartnews24passowrd”, startnews24passowrd);

//コレクションクラス
ArrayList pairs = new ArrayList();
pairs.add(pair1);
pairs.add(pair2);

//オブジェクトリクエストの定義
try {
HttpEntity requestEntity = new UrlEncodedFormEntity(pairs);

httpPost.setEntity(requestEntity);
HttpResponse response = httpClient.execute(httpPost);

if(response.getStatusLine().getStatusCode() == 200){

HttpEntity entity = response.getEntity();
BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
String reslut = reader.readLine();
System.out.println(reslut);
Log.d(“HttpPost”,”result”+reslut);

}

} catch (Exception e) {
e.printStackTrace();
}
}
}
}