Call<Profile> getCurrentUser(@Header("Cookie") String cookieA);
@Override
protected void onPostExecute(Spanned spanned) {
super.onPostExecute(spanned);
title.setText(strTitle);
textView.setText(spanned);
for (List<String> id : ids) {
VideoFragment f = VideoFragment.newInstance(id);
FrameLayout frameLayout = new FrameLayout(NewsContent.this);
frameLayout.setTag(id);
linearLayout.addView(frameLayout);
getSupportFragmentManager().beginTransaction().replace(frameLayout.getId(), f).commit();
}
progressDialog.dismiss();
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/scrollContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</ScrollView>
</RelativeLayout>
public class MainActivity extends AppCompatActivity {
LinearLayout linearLayout;
String[] ids = new String[]{"1", "2", "3", "4", "5"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
linearLayout = (LinearLayout) findViewById(R.id.scrollContainer);
int position = 0;
for (String id : ids) {
FrameLayout fm = new FrameLayout(this);
fm.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 500));
linearLayout.addView(fm);
fm.setId(++position);
BlankFragment fragment = BlankFragment.newInstance(id);
getFragmentManager().beginTransaction().replace(position, fragment, id).commit();
}
}
}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/hello_blank_fragment" />
</FrameLayout>
public class BlankFragment extends Fragment {
private static final String ARG_PARAM1 = "param1";
private String mParam1;
private TextView title;
public static BlankFragment newInstance(String param1) {
BlankFragment fragment = new BlankFragment();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
fragment.setArguments(args);
return fragment;
}
public BlankFragment() {}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_blank, container, false);
title = (TextView) v.findViewById(R.id.title);
title.setText(mParam1);
return v;
}
}
@GET("/user")
Call<User> getUser(@Header("Authorization") String authorization)
public interface KotomatrixService {
@FormUrlEncoded
@POST("http://kotomatrix.ru")
Call<String> login(@Field("login") String login, @Field("password") String pass, @Field("act") String act, @Field("remember") String remember);
}
public class ApiFactory {
private static final int CONNECT_TIMEOUT = 15;
private static final int WRITE_TIMEOUT = 60;
private static final int TIMEOUT = 60;
private static final OkHttpClient CLIENT = new OkHttpClient();
static {
CLIENT.setConnectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS);
CLIENT.setWriteTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS);
CLIENT.setReadTimeout(TIMEOUT, TimeUnit.SECONDS);
}
@NonNull
public static KotomatrixService getKotomatrixService() {
return getRetrofit().create(KotomatrixService.class);
}
@NonNull
private static Retrofit getRetrofit() {
return new Retrofit.Builder()
.baseUrl("http://kotomatrix.ru")
.addConverter(String.class, new StringConverter())
.client(CLIENT)
.build();
}
}
public final class StringConverter implements Converter<String> {
@Override
public String fromBody(ResponseBody body) throws IOException {
return body.string();
}
@Override
public RequestBody toBody(String value) {
return RequestBody.create(MediaType.parse("text/plain"), value);
}
}
public class MainActivity extends AppCompatActivity implements Callback<String> {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
KotomatrixService service = ApiFactory.getKotomatrixService();
Call<String> call = service.login("testUser", "testUser", "login", "true");
call.enqueue(MainActivity.this);
}
@Override
public void onResponse(Response<String> response) {
if (response.isSuccess()) {
// ищем куку и сохраняем
}
}
@Override
public void onFailure(Throwable t) {
}
}
public ListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
final TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.ListView, defStyleAttr, defStyleRes);
final CharSequence[] entries = a.getTextArray(R.styleable.ListView_entries);
if (entries != null) {
setAdapter(new ArrayAdapter<>(context, R.layout.simple_list_item_1, entries));
}
...
<resources>
<declare-styleable name="ListView">
<attr name="entries" format="reference"/>
</declare-styleable>
</resources>
public class MyListView extends ListView {
public MyListView(Context context) {
super(context);
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListView, 0, 0);
final CharSequence[] entries = a.getTextArray(R.styleable.ListView_entries);
if (entries != null) {
setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, entries));
}
a.recycle();
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<test.MyListView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:entries="@array/options">
</test.MyListView>
</RelativeLayout>
public class MyListView extends ListView {
public MyListView(Context context) {
super(context);
}
public MyListView(Context context, AttributeSet attrs) {
super(context, attrs);
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListView, 0, 0);
final int resId = a.getResourceId(R.styleable.ListView_entries, 0);
final CharSequence[] entries = getResources().getTextArray(resId);
if (entries != null) {
setAdapter(new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, entries));
}
a.recycle();
}
}
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListView, 0, 0);
final CharSequence[] entries = a.getTextArray(R.styleable.ListView_entries);
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListView, 0, 0);
final int resId = a.getResourceId(R.styleable.ListView_entries, 0);
final CharSequence[] entries = getResources().getTextArray(resId);
UID|HASH|Version|Deleted
1|c4ca4238a0b923820dcc509a6f75849b|1|0
2|c81e728d9d4c2f636f067f89cc14862c|2|0
3|eccbc87e4b5ce2fe28308fd9f2a7baf3|4|0
4|a87ff679a2f3e71d9181a67b7542122c|8|1
5|e4da3b7fbbce2345d7772b0674a318d5|6|0
{
"version": 8,
"changed": [
{
"UID": 3,
"HASH": "eccbc87e4b5ce2fe28308fd9f2a7baf3"
},
{
"UID": 5,
"HASH": "e4da3b7fbbce2345d7772b0674a318d5"
}
],
"deleted": [
{
"UID": 4
}
]
}
Не надо бегать по спискам и сравнивать хэши.public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment fragment = MainActivityFragment.newInstance(this);
ft.replace(R.id.main, fragment);
ft.commit();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment fragment = SettingsActivityFragment.newInstance(this);
ft.replace(R.id.main, fragment);
ft.addToBackStack(null);
ft.commit();
}
return super.onOptionsItemSelected(item);
}
}
public class MainActivityFragment extends Fragment {
public static Fragment newInstance(Context context) {
MainActivityFragment f = new MainActivityFragment();
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_main, container, false);
}
}
public class SettingsActivityFragment extends Fragment {
public static Fragment newInstance(Context context) {
SettingsActivityFragment f = new SettingsActivityFragment();
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_settings_activity, container, false);
}
}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/AC_ListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"></ListView>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="top">
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/GeneralSettingsText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="GeneralSettingsText"
android:textStyle="bold" />
<View
android:id="@+id/AdvCount"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_gravity="center_vertical"
android:layout_marginTop="5dp"
android:background="#fccccccc" />
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="checkBox1" />
<TextView
android:id="@+id/ShowedText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:text="ShowedText"
android:textStyle="bold" />
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:ems="10"
android:inputType="textMultiLine"
android:lines="3" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="textView2"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
byte[] mls = new byte[11];
mls[0] = addCRC(new byte[]{1, 0x5, 11, 5 ,0, 0}); //10 сек
mls[1] = addCRC(new byte[]{1, 0x5, 11, 1 ,0, 0}); //0 сек
mls[2] = addCRC(new byte[]{1, 0x5, 0, 5 ,0, 0}); //30 сек
mls[3] = addCRC(new byte[]{1, 0x5, 1, 5 ,0, 0}); //5 сек
mls[4] = addCRC(new byte[]{1, 0x5, 2, 5 ,0, 0}); //5 сек
mls[5] = addCRC(new byte[]{1, 0x5, 3, 5 ,0, 0}); //5 сек
mls[6] = addCRC(new byte[]{1, 0x5, 4, 5 ,0, 0}); //5 сек
mls[7] = addCRC(new byte[]{1, 0x5, 5, 5 ,0, 0}); //5 сек
mls[8] = addCRC(new byte[]{1, 0x5, 6, 5 ,0, 0}); //5 сек
mls[9] = addCRC(new byte[]{1, 0x5, 7, 5 ,0, 0}); //5 сек
mls[10] = addCRC(new byte[]{1, 0x5, 8, 5 ,0, 0}); //5 сек
public int[] delays = new int[11]{10,0,30,5,5,5,5,5,5,5,5};
int shift;
public void onClickWrite(View v) {
int len = mls.length;
for (int i = 0; i < len; i++) {
shift += delays[i];
new Handler(Looper.getMainLooper()).postDelayed( new Runnable() {
public void run(){
byte b = mls[i];
mPhysicaloid.write(b, b.length);
}
}, shift);
}
}
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:id="@+id/fragment">
</FrameLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment, new MainActivityFragment()).commit();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main, container, false);
btn = (Button) view.findViewById(R.id.button2);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment, new BlankFragment()).addToBackStack(null).commit();
}
});
return view;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_blank, container, false);
btn = (Button) view.findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getActivity().getSupportFragmentManager().popBackStack();
}
});
return view;
}
URL url = new URL("http://backend.com/api.php");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
try {
urlConnection.setDoOutput(true);
urlConnection.setChunkedStreamingMode(0);
OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream());
writeStream(out);
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
readStream(in);
finally {
urlConnection.disconnect();
}