package com.ye.HttpClientTest;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TextView;
public class HttpClientTest extends Activity implements Button.OnClickListener {
/** Called when the activity is first created. */
protected static final int GUIUPDATEIDENTIFIER = 0x101;
public TextView accept;
public Button send;
public EditText showEditText;
public ProgressBar progressBar;
public String urlString,dataString;
private String msg="";
public class HttpClientReceiver extends BroadcastReceiver{
//接收广播
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
Log.v("HttpClientTest", "onReceive");
progressBar.setVisibility(View.GONE);
msg = intent.getStringExtra("msg");
accept.setText(msg);
}
}
@Override
public void onCreate(Bundle savedInstanceState) {
Log.i("HttpClientTest", "onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
accept= (TextView)findViewById(R.id.accept);
send = (Button) findViewById(R.id.send);
showEditText = (EditText) findViewById(R.id.show);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setVisibility(View.GONE);
send.setOnClickListener(this);
//注册广播器
IntentFilter filter=new IntentFilter("com.ye.service.msg");
HttpClientReceiver receiver=new HttpClientReceiver();
registerReceiver(receiver,filter);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Log.i("HttpClientTest", "onClick()");
progressBar.setVisibility(View.VISIBLE);
urlString = "http://api.showji.com/locating/?m="+showEditText.getText()+"&output=text";
Intent intent = new Intent("com.ye.HttpClientTest.HttpClientTestService");
Bundle bundle = new Bundle();
bundle.putString("url", urlString);
intent.putExtras(bundle);
intent.setClass(HttpClientTest.this, HttpClientTestService.class);
startService(intent);
}
}
package com.ye.HttpClientTest;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
public class HttpClientTestService extends Service {
public String resultString = "";
public String urlString = "";
String websiteData = null;
DefaultHttpClient client;
Intent intent;
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Log.v("HttpClientTestService", "in onStart()");
Bundle bundle = intent.getExtras();
urlString = bundle.getString("url");
new Thread(mRunnable).start();
}
Runnable mRunnable = new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Log.i("Thread", "Thread is start");
resultString = getUrlData(urlString);
sendMsg(resultString);
}
};
//onCreate在service初始化的时候被调一次,直到service生命周期的结束
@Override
public void onCreate() {
Log.i("HttpClientTestService", "in onCreate()");
client = new DefaultHttpClient();
intent = new Intent("com.ye.service.msg");
}
public String getUrlData(String url){
try {
URI uri = new URI(url);
HttpGet method = new HttpGet(uri);
HttpResponse res = client.execute(method);
InputStream data = res.getEntity().getContent();
websiteData = generateString(data);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (URISyntaxException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return websiteData;
}
public String generateString(InputStream stream) {
InputStreamReader reader = new InputStreamReader(stream);
BufferedReader buffer = new BufferedReader(reader);
StringBuilder sb = new StringBuilder();
try {
String cur;
while ((cur = buffer.readLine()) != null) {
sb.append(cur + "\n");
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
stream.close();
buffer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return sb.toString();
}
// 发送广播信息
private void sendMsg(String msg){
Log.i("HttpClientTestService", "sendMsg()");
// 指定广播目标的 action (注:指定了此 action 的 receiver 会接收此广播)
// 需要传递的参数
intent.putExtra("msg", msg);
// 发送广播
this.sendBroadcast(intent);
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ye.HttpClientTest"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".HttpClientTest"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name="HttpClientTestService">
<intent-filter>
<action android:name="com.ye.HttpClientTest.HttpClientTestService"/>
</intent-filter>
</service>
</application>
<uses-permission android:name="android.permission.INTERNET" />
</manifest>
Spinner
作为下拉选项列表 还是非常不错 且易用的 同时 也存在一些局限性 比如: 标题栏 下拉栏 显示内容必须一致 这使得其
实用性大打折扣
1. 先说说其不足之处 即: 标题 下拉 显示内容 相同问题:
* 定义待显示内容 以TextView为例:
String[] content = { "eoe.android","eoe.mobile","eoe.mark","eoe.rd","eoe.mobile" };
* 定义 CustomAdapter :
public class CustomAdapter extends BaseAdapter { Activity activity; public CustomAdapter(Activity a){ activity = a; } @Override public int getCount() { // TODO Auto-generated method stub return content.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub TextView tv = new TextView(activity); tv.setText(content[position]); tv.setTextSize(20); return tv; } }
* emulator 运行效果 可以看出 标题 下拉 显示内容 是一样的
2. 使得 标题 下拉 二者显示内容不同
* 定义标题显示内容:title 下拉继续使用上面定义的content
String[] title = { "0","1","2","3","4","5" };
* 定义 CustomSpinnerAdapter:
public class CustomSpinnerAdapter implements SpinnerAdapter { Activity activity; public CustomSpinnerAdapter(Activity a){ activity = a; } @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub TextView tv = new TextView(activity); tv.setText(content[position]); tv.setTextSize(20); tv.setTextColor(Color.RED); return tv; } @Override public int getCount() { // TODO Auto-generated method stub return content.length; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public int getItemViewType(int position) { // TODO Auto-generated method stub return IGNORE_ITEM_VIEW_TYPE; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub TextView tv = new TextView(activity); tv.setText(title[position]); tv.setTextColor(Color.GREEN); return tv; } @Override public int getViewTypeCount() { // TODO Auto-generated method stub return content.length; } @Override public boolean hasStableIds() { // TODO Auto-generated method stub return false; } @Override public boolean isEmpty() { // TODO Auto-generated method stub return false; } @Override public void registerDataSetObserver(DataSetObserver observer) { // TODO Auto-generated method stub } @Override public void unregisterDataSetObserver(DataSetObserver observer) { // TODO Auto-generated method stub } }
* emulator 运行截图 注意二者的不同显示
已+
ubuntu samba配置
关键字: ubuntu samba
转自:
http://www.5ilinux.com/samba.html
一、samba要求:
公司有财务,技术,领导3个部门,我们分别为3个部门建立3个用户组为caiwu,network,lingdao;
三个部门里各有2个用户,我们建用户分别为caiwu01,caiwu02,network01,network02,lingdao01,lingdao02
然后我们分别就公司的具体情况建立相应的目录及访问权限,通过以下的例子,希望大家能在平时的工作中灵活的应用samba的安全权限来设置你们的samba文件服务器。
1。首先服务器采用用户验证的方式,每个用户可以访问自己的宿主目录,并且只有该用户能访问宿主目录,并具有完全的权限,而其他人不能看到你的宿主目录。
2。建立一个caiwu的文件夹,希望caiwu组和lingdao组的人能看到,network02也可以访问,但只有caiwu01有写的权限。
3。建立一个lindao的目录,只有领导组的人可以访问并读写,还有network02也可以访问,但外人看不到那个目录
4。建议一个文件交换目录exchange,所有人都能读写,包括guest用户,但每个人不能删除别人的文件。
5。建议一个公共的只读文件夹public,所有人只读这个文件夹的内容。
二、操作
#groupadd caiwu
#groupadd network
#groupadd lingdao
#useradd caiwu01 -g caiwu
#useradd caiwu02 -g caiwu
#useradd network01 -g network
#useradd network02 -g network
#useradd lingdao01 -g lingdao
#useradd lingdao02 -g lingdao
然后我们使用smbpasswd -a caiwu01的命令为6个帐户分别添加到samba用户中
#mkdir /home/samba
#mkdir /home/samba/caiwu
#mkdir /home/samba/lingdao
#mkdir /home/samba/exchange
#mkdir /home/samba/public
我们为了避免麻烦可以在这里把上面所有的文件夹的权限都设置成777,我们通过samba灵活的权限管理来设置上面的5点要求。
三、vim /etc/samba/smb.conf
[global]
workgroup = Ubuntu
server string = Ubuntu Samba Test
security = user
encrypt passwords = true
smb passwd file = /etc/samba/smbpasswd
[homes]
comment = Home Directories
browseable = no
writable = yes
valid users = %S
create mode = 0664
directory mode = 0775
#homes段满足第1条件,需要说明的是需要在/home目录里手动为每位用户建立相应的家目录,并设置好相应权限。
[caiwu]#满足我们的第2要求
comment = caiwu
path = /home/samba/caiwu
public = no
valid users = @caiwu,@lingdao,network02
write list = caiwu01
[lingdao]#满足我们的第3要求
comment = Lingdao
path = /home/samba/lingdao
public = no
valid users = @lingdao,network02
writeable = yes
[exchage]
comment = Exchange File Directory
path = /home/samba/exchange
public = yes
writable = yes
#exchange段基本能满足我们的第4要求,但不能满足每个人不能删除别人的文件这个条件,即使里设置了mask也是没用,其实这个条件只要unix设置一个粘着位就行
chmod -R 1777 /home/samba/exchange
注意这里权限是1777,类似的系统目录/tmp也具有相同的权限,这个权限能实现每个人能自由写文件,但不能删除别人的文件这个要求"有些疑问!!!"
[Public]#满足我们的第5要求。
comment = read only Public
path = /home/samba/public
public = yes
read only = yes
重启服务:#/etc/rc.d/init.d/smb restart
到此配置结束,可以使用命令:testparm /etc/samba/smb.conf检测samba配置文件
四、验证samba
在windows下直接在运行里输入:\\server
然后输入相应用户名和密码就可以访问
在linux下可以使用:
smbclient //服务器ip/caiwu -U caiwu01
#以caiwu01用户的名义登录caiwu目录
smbmount //服务器ip/caiwu /mnt/caiwu -o username=caiwu01
#把服务器的财务目录映射到本地的/mnt/caiwu目录
转自:
http://www.5ilinux.com/samba.html