#StackBounty: #android #retrofit #multipart is it possible to pass a single item as multipart using retrofit?

Bounty: 100

 @Multipart
@POST("/api/add-deal/")
public void addDeal(@Body Deal deal, @Part("image")TypedFile image,Callback<Response> callback);

I want to send only the image as multipart and the rest as is.Is there any possible way ? Even I tried to add TypedFile inside my Deal model but unable to annotate with @part


Get this bounty!!!

#StackBounty: #android #android-viewpager #recyclerview #adapter RecyclerView Items are not changing

Bounty: 50

I have a RecyclerView in a fragment which is repeating in TabLayout. I am having the problem of unchanged view in RecyclerView. I have a spinner on each tab. I want to change the data when spinner items get selected.

My cases:

  1. when switching between tabs – items changed
  2. when selecting another value in the spinner in the first tab –items not changed. (but data is changing in adapter class. Found it using breakpoints).

    Note: In this case when switching the tab, the items get changed to
    the spinner selected items in the previous tab. And then it disappears
    and displaying the current items in the tab.

  3. when selecting another value in the spinner in the last tab –items changed.

My view pager adapter class


public class StudentViewPagerAdapter extends FragmentStatePagerAdapter {
    private final List<StudentList> mFragmentList = new ArrayList<>();
    private final List<Clazz> mFragmentTitleList = new ArrayList<>();
    public StudentViewPagerAdapter(FragmentManager fm) {
        super(fm);
    }
    public void addFragment(StudentList fragment,Clazz clazz){
        mFragmentList.add(fragment);
        mFragmentTitleList.add(clazz);
    }
    @Override
    public Fragment getItem(int position) {
        return mFragmentList.get(position).newInstance(mFragmentTitleList.get(position));
    }

    @Override
    public int getCount() {
        return mFragmentList.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mFragmentTitleList.get(position).getName();
    }
}

my RecyclerView adapter class

public class PeopleAdapter extends RecyclerView.Adapter<PeopleAdapter.MyViewHolder> implements View.OnClickListener {
    private List<Student> dataList;
    private Context context;
    private Clicker clicker;
    public PeopleAdapter(List<Student> data, Context context, Clicker clicker) {
        this.dataList = data;
        this.context = context;
        this.clicker = clicker;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.people_list_item, parent, false);

        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Student data=dataList.get(position);
        holder.email.setText(data.getEmail());
        holder.name.setText(data.getName());
        holder.phone.setText(data.getPhone());
        Glide.with(context).load(Method.getImageUrl(MyConfiguration.STUDENT_IMAGE_URL,
                data.getStudentId())).asBitmap().into(holder.profilePic);
        holder.edit.setOnClickListener(this);
        holder.edit.setTag(position);
    }

    @Override
    public int getItemCount() {
        return dataList.size();
    }

    @Override
    public void onClick(View v) {
        clicker.OnItemClicked((int) v.getTag(),null);
    }


    static class MyViewHolder extends RecyclerView.ViewHolder {
    @BindView(R.id.name)
        TextView name;
        @BindView(R.id.email)
        TextView email;
        @BindView(R.id.phone)
        TextView phone;
        @BindView(R.id.image)
        ImageView profilePic;
        @BindView(R.id.imageedit)
        ImageView edit;
    MyViewHolder(View view) {
        super(view);
        ButterKnife.bind(this,view);
    }
}

}

tab fragments

    public class StudentList extends Fragment implements SectionChanger {
        @BindView(R.id.studentlist)
        RecyclerView mRecyclerview;
        CompositeDisposable disposable;
        private Unbinder unbinder;
        private Clazz clazz;
        private Requester requester;

        public StudentList() {
            StudentInformation.bindSectionChangeListener(this);
        }
        public static StudentList newInstance(Clazz clazz) {
            StudentList fragment=new StudentList();
            Bundle args = new Bundle();
            args.putSerializable(MyConfiguration.SECTIONS, clazz);
            fragment.setArguments(args);
            return fragment;
        }
        @Override
        public void onDestroyView() {
            super.onDestroyView();
            unbinder.unbind();
            disposable.clear();
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            // Inflate the layout for this fragment
            View view = inflater.inflate(R.layout.fragment_student_list, container, false);
            unbinder = ButterKnife.bind(this, view);
            LinearLayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
            mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
            mRecyclerview.setLayoutManager(mLayoutManager);
            initializeRetrofit();
            if (getArguments() != null) {
                clazz = (Clazz) getArguments().getSerializable(MyConfiguration.SECTIONS);
                loadStudentJson(clazz != null ? clazz.getClassId() : null,
                        clazz != null ? clazz.getSections().get(0).getSectionId() : null);
            }
            return view;
        }

        /**
         * Load students list
         */
        public void loadStudentJson(String class_id,String section_id) {


            disposable = new CompositeDisposable(requester.getStudentsInSection(class_id,section_id)
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribeOn(Schedulers.io())
                    .subscribe(
                            this::handleResponse,
                            this::handleError
                    )
            );
        }

        private void handleResponse(List<Student> list) {
            PeopleAdapter adapter=new PeopleAdapter(list, getActivity(),
                    (position, name) -> Toast.makeText(getActivity(), position, Toast.LENGTH_LONG).show());
            mRecyclerview.setAdapter(adapter);
            adapter.notifyDataSetChanged();
        }

        private void handleError(Throwable error) {
            Toast.makeText(getActivity(), "Error " + error.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
        }

        @Override
        public void ChangeData(Section section) {
            loadStudentJson(section.getClassId(),section.getSectionId());
        }
        public void initializeRetrofit(){
            HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
            interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            CookieHandler handler=new Cookies(getActivity());
            //ClearableCookieJar cookieJar = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(getActivity()));
            OkHttpClient client = new OkHttpClient.Builder()
                    .addInterceptor(interceptor)
                    .cookieJar(new JavaNetCookieJar(handler))
                    .build();

            requester = new Retrofit.Builder()
                    .baseUrl(MyConfiguration.BASE_URL)
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .addConverterFactory(JacksonConverterFactory.create())
                    .client(client)
                    .build().create(Requester.class);
        }
    }

Viewpager setup fragment

public class StudentInformation extends Fragment implements TabLayout.OnTabSelectedListener, AdapterView.OnItemSelectedListener {
    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    private Unbinder unbinder;
    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    CompositeDisposable disposable;
    List<Section> sectionsList=new ArrayList<>();
    private OnConnectingFragments mListener;
    @BindView(R.id.tabs)
    TabLayout mTabLayout;
    @BindView(R.id.viewpager)
    ViewPager viewPager;
    @BindView(R.id.secSelector)
    Spinner spinner;
    @BindView(R.id.className)
    TextView className;
    private static SectionChanger sectionChanger;
    public StudentInformation() {
        // Required empty public constructor
    }

    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment StudentInformation.
     */
    // TODO: Rename and change types and number of parameters
    public static StudentInformation newInstance(String param1, String param2) {
        StudentInformation fragment = new StudentInformation();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        disposable.clear();
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_student_information, container, false);
        unbinder = ButterKnife.bind(this, view);
        LoadDataAndSetupViewPager();
        //setupViewPager(viewPager);
        mTabLayout.setupWithViewPager(viewPager);
        mTabLayout.addOnTabSelectedListener(this);
        spinner.setOnItemSelectedListener(this);
//        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, MyConfiguration.CLASS_SECTIONS);
//        spinner.setAdapter(arrayAdapter);

        return view;
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Fragment fragment,String tag) {
        if (mListener != null) {
            mListener.onClickedMenu(fragment,tag);
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnConnectingFragments) {
            mListener = (OnConnectingFragments) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }
    /**
     * This interface must be implemented by activities that contain this
     * fragment to allow an interaction in this fragment to be communicated
     * to the activity and potentially other fragments contained in that
     * activity.
     * <p>
     * See the Android Training lesson <a href=
     * "http://developer.android.com/training/basics/fragments/communicating.html"
     * >Communicating with Other Fragments</a> for more information.
     */
    /*private void setupViewPager(ViewPager viewPager) {
        StudentViewPagerAdapter adapter = new StudentViewPagerAdapter(getFragmentManager());
        //adapter.addFragment(new StudentList(),"exam");

        for (String claz: MyConfiguration.CLASS)
            adapter.addFragment(new StudentList(), claz);
        viewPager.setAdapter(adapter);
    }*/
    @OnClick(R.id.add)
    public void OnClicked(LinearLayout view){
        onButtonPressed(new AddStudent(),"addStudent");
    }

    @Override
    public void onTabSelected(TabLayout.Tab tab) {
        className.setText(String.format(getString(R.string.class_name), tab.getPosition()+1));
    }

    @Override
    public void onTabUnselected(TabLayout.Tab tab) {

    }

    @Override
    public void onTabReselected(TabLayout.Tab tab) {

    }
    public void LoadDataAndSetupViewPager() {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        ClearableCookieJar cookieJar =
                new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(getActivity()));
        OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

        Requester requester=new Retrofit.Builder()
                .baseUrl(MyConfiguration.BASE_URL)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(JacksonConverterFactory.create())
                .client(client)
                .build().create(Requester.class);
        disposable=new CompositeDisposable(requester.getClasses()    ////GETTING CLASSES////
                .observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .flatMapIterable(clazzs -> clazzs)
                .flatMap(clazz -> requester.getDivision(clazz.getClassId())  ////GETTING SECTIONS////
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribeOn(Schedulers.io())
                        .flatMapIterable(sections -> sections)
                        .doOnNext(section -> {sectionsList.add(section);
                            Log.v("section_id",section.getSectionId());})
                        .takeLast(1)
                        .map(section -> clazz)
                )
                .doOnNext(clazz -> {clazz.setSections(sectionsList);
                    Log.v("List Size",sectionsList.size()+"");
                    sectionsList=new ArrayList<>();
                })
                .toList()
                .subscribe(this::SetupViewPager, throwable -> Log.e("retroerror",throwable.toString())));

    }
    public void SetupViewPager(List<Clazz> classList){
        StudentViewPagerAdapter adapter = new StudentViewPagerAdapter(getFragmentManager());
        //adapter.addFragment(new StudentList(),"exam");

        for (Clazz claz: classList){
            adapter.addFragment(new StudentList(), claz);
        }

        viewPager.setAdapter(adapter);
        viewPager.setOffscreenPageLimit(3);
        viewPager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                super.onPageSelected(position);
                List<Section>sections=classList.get(position).getSections();
                ArrayAdapter<Section> arrayAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_dropdown_item, sections);
                spinner.setAdapter(arrayAdapter);
            }
        });
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                Section section= (Section) parent.getItemAtPosition(position);
                sectionChanger.ChangeData(section);
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }
    public static void bindSectionChangeListener(SectionChanger changer){
        sectionChanger=changer;
    }
}

The question is: Why the data get unchanged when selecting options in the spinner sometimes? (look my cases)


Get this bounty!!!

#StackBounty: #android #android-layout #android-viewpager #android-tabs #android-tablayout how to use tabContentStart to start content …

Bounty: 50

I am using TabLayout and ViewPager

<android.support.v4.view.ViewPager
        android:id="@+id/view_pager_social_profiles"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"></android.support.v4.view.ViewPager>

<android.support.design.widget.TabLayout
        android:id="@+id/tab_layout_social_profiles"
        android:layout_width="match_parent"
        android:layout_height="112dp"
        app:tabContentStart="72dp"
        app:tabGravity="center"
        app:tabIndicatorHeight="0dp"
        app:tabMode="scrollable"></android.support.design.widget.TabLayout>

I want to start tab content from the middle of screen so if there is only one tab it will be aligned exactly center of screen (horizontally) and also selected tab will be always in center.


Get this bounty!!!

#StackBounty: #ubuntu #compiling #gcc #android Swift for Android: `ld` cannot find `-lgcc` in swift for android compilation linking step

Bounty: 100

I’m trying to compile Swift code on Ubuntu 16.04 LTS, following these instructions fairly closely. I was able to download the NDK r14 okay, download the libicu tools and build them, and download the swift source and build that against the libicu tools. I get all the way down to compiling actual swift code and get this:

#build.sh 
#(I symlinked the androideabi ld.gold to /usr/bin/ld.armv7, based on a swift bug ticket's advice. Thats the only thing different from the instructions)

/home/mike/workspace/swift-source/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swiftc 
-use-ld=armv7 
-tools-directory /home/mike/workspace/android-ndk-r14/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin 
-target armv7-none-linux-androideabi 
-sdk /home/mike/workspace/android-ndk-r14/platforms/android-21/arch-arm 
-L /home/mike/workspace/android-ndk-r14/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a 
-L /home/mike/workspace/android-ndk-r14/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9 
hello.swift


#output
mike@mike-VirtualBox:~/workspace/HelloSwift$ ./build.sh 
/usr/bin/ld.armv7: error: cannot find -lgcc
/usr/bin/ld.armv7: error: cannot find -lgcc
/usr/bin/ld.armv7: error: cannot find -lgcc
/usr/bin/ld.armv7: error: cannot find -lgcc

I don’t have a ton of experience being this far down the toolchain, but I deeeefinitely have gcc installed, and gcc-multilib, and LD_LIBRARY_PATH set to help ld find gcc, and I’ve rebuild the ld cache with ldconfig.


Get this bounty!!!

#StackBounty: #c# #android #visual-studio #mono #xamarin.android Pinging IP or HOSTNAME with Xamarin not working as expected

Bounty: 50

I’m trying this code and it returns always TTL Expired even if the ip or hostname is unreachable , timeout or any other diferrent problem :

using System.Net.NetworkInformation;

PingReply Reply = await pingo.SendPingAsync(text_ip.Text, 4000, buffer, options);
        Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
        switch (Reply.Status)
        {
            case IPStatus.Success:

                Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                break;

            case IPStatus.TimedOut:

                Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                break;

            case IPStatus.TimeExceeded:

                Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                break;

            case IPStatus.DestinationHostUnreachable:


               Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                break;

            case IPStatus.DestinationNetworkUnreachable:

                Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                break;

            case IPStatus.DestinationUnreachable:

                Toast.MakeText(Activity, Reply.Status.ToString(), ToastLength.Long).Show();
                break;
        }

I found a bug at https://github.com/mono/mono/blob/master/mcs/class/System/System.Net.NetworkInformation/Ping.cs (line 339)
That calls the system ping command and checks the exit code:

if (!ping.WaitForExit (timeout) || (ping.HasExited && ping.ExitCode == 2))
    status = IPStatus.TimedOut;
else if (ping.ExitCode == 0)
    status = IPStatus.Success;
else if (ping.ExitCode == 1)
    status = IPStatus.TtlExpired;

So TTL expired is set when there was no timeout, no error or success (exit code 2 or 0), and the exit code was 1.

If ping does not receive any reply packets at all it will exit with code 1. If a packet count and deadline are both specified, and fewer than count packets are received by the time the deadline has arrived, it will also exit with code 1. On other error it exits with code 2. Otherwise it exits with code 0. This makes it possible to use the exit code to see if a host is alive or not.

So a return value of 1 indicates that no response has been received (for various reasons) and the Mono implementation sets the TTL expired status in this case. I would expect that a time out status would be returned in such cases. But it seems that the timeout detection of the Mono implementation is not triggered here (e.g. because the ping command exits upon on it’s own timeout before).

So there is other possible solutions:

To treat a TTL expired as host not alive (but this will then ignore real TTL expired detections)

Anyway can somebody show another way to do this with a example of Ping request with exec from Java.Lang.Process and to get from the reply time, info , statistics or other values ?


Get this bounty!!!

#StackBounty: #android #cordova #apk Manipulating the UI of existing native applications at runtime

Bounty: 100

I know this sounds “hacky” but I would like to personalize some UIs of the applications I have already installed in my Android. E.g. Using the same fonts, colors, etc. I know this sounds weird but I’m not thinking in creating an app for others but me, so it is not a problem if I have to root my phone or have it in debug mode. Any clue?

PS: I already saw some answers suggesting to decompress/compress the apk, but I don’t want to modify the applications’ sources, just injecting some style (as Stylish extension do it for Web applications) at runtime.

PS2: As Cordova apps are built with Web technologies, it may be possible to have a DOM to manipulate but how to do it from the outside?

Thanks in advance!


Get this bounty!!!

#StackBounty: #laptop #android Unable to connect to websites which don't start with www

Bounty: 100

I have created hotspot from my Andriod mobile and using Internet on laptop Windows 7 but I’m unable to connect to websites which don’t start with www..

The error:

If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web

Should the settings be done on mobile or laptop? What should I change?

Note I am using mobile data. Websites starting with www. are working fine. The problem doesn’t occur on my phone. Also everything is OK when my laptop uses LAN.


Get this bounty!!!

#StackBounty: #laptop #android Unable to connect to websites which don't start with www

Bounty: 100

I have created hotspot from my Andriod mobile and using Internet on laptop Windows 7 but I’m unable to connect to websites which don’t start with www..

The error:

If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web

Should the settings be done on mobile or laptop? What should I change?

Note I am using mobile data. Websites starting with www. are working fine. The problem doesn’t occur on my phone. Also everything is OK when my laptop uses LAN.


Get this bounty!!!

#StackBounty: #laptop #android Unable to connect to websites which don't start with www

Bounty: 100

I have created hotspot from my Andriod mobile and using Internet on laptop Windows 7 but I’m unable to connect to websites which don’t start with www..

The error:

If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web

Should the settings be done on mobile or laptop? What should I change?

Note I am using mobile data. Websites starting with www. are working fine. The problem doesn’t occur on my phone. Also everything is OK when my laptop uses LAN.


Get this bounty!!!

#StackBounty: #laptop #android Unable to connect to websites which don't start with www

Bounty: 100

I have created hotspot from my Andriod mobile and using Internet on laptop Windows 7 but I’m unable to connect to websites which don’t start with www..

The error:

If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web

Should the settings be done on mobile or laptop? What should I change?

Note I am using mobile data. Websites starting with www. are working fine. The problem doesn’t occur on my phone. Also everything is OK when my laptop uses LAN.


Get this bounty!!!